为了账号安全,请及时绑定邮箱和手机立即绑定

关于java中对象引用的理解?

关于java中对象引用的理解?

JustV 2017-02-20 08:59:04

比如如下语句:

int[] A = new int[3];

int a;

a = A[1];

a = 123;

System.out.println(A[1]);

这时输出的A[1]仍然是系统默认的初始值0,如果想要通过a来改变A[1]的值(类似C++里指针的效果?),应该如何实现?

如果不是基础数据类型,而是自己定义的类,是否就能达到效果?

查看完整描述

5 回答

?
慕莱坞8333017

TA贡献5405条经验 获得超0个赞

https://www.imooc.com/wenda/detail/335776

https://www.imooc.com/wenda/detail/334849

https://www.imooc.com/wenda/detail/339222

https://www.imooc.com/wenda/detail/343628

https://www.imooc.com/wenda/detail/332927

https://www.imooc.com/wenda/detail/340266

https://www.imooc.com/wenda/detail/351957

https://www.imooc.com/wenda/detail/346631

https://www.imooc.com/wenda/detail/337048

https://www.imooc.com/wenda/detail/351716

https://www.imooc.com/wenda/detail/342501

https://www.imooc.com/wenda/detail/337339

https://www.imooc.com/wenda/detail/345550

https://www.imooc.com/wenda/detail/343419

https://www.imooc.com/wenda/detail/352867

https://www.imooc.com/wenda/detail/333896

https://www.imooc.com/wenda/detail/355123

https://www.imooc.com/wenda/detail/355079

https://www.imooc.com/wenda/detail/340787

https://www.imooc.com/wenda/detail/352619

https://www.imooc.com/wenda/detail/340158

https://www.imooc.com/wenda/detail/343197

https://www.imooc.com/wenda/detail/340192

https://www.imooc.com/wenda/detail/349514

https://www.imooc.com/wenda/detail/347740

https://www.imooc.com/wenda/detail/347404

https://www.imooc.com/wenda/detail/347404

https://www.imooc.com/wenda/detail/336695

https://www.imooc.com/wenda/detail/343114

https://www.imooc.com/wenda/detail/351673

https://www.imooc.com/wenda/detail/345294

https://www.imooc.com/wenda/detail/342445

https://www.imooc.com/wenda/detail/336804

https://www.imooc.com/wenda/detail/347347

https://www.imooc.com/wenda/detail/343040

https://www.imooc.com/wenda/detail/336965

https://www.imooc.com/wenda/detail/332467

https://www.imooc.com/wenda/detail/350659

https://www.imooc.com/wenda/detail/350258

https://www.imooc.com/wenda/detail/348409

https://www.imooc.com/wenda/detail/340672

https://www.imooc.com/wenda/detail/334403

https://www.imooc.com/wenda/detail/335156

https://www.imooc.com/wenda/detail/354876

https://www.imooc.com/wenda/detail/352291

https://www.imooc.com/wenda/detail/349132

https://www.imooc.com/wenda/detail/336677

https://www.imooc.com/wenda/detail/351327

https://www.imooc.com/wenda/detail/337659

https://www.imooc.com/wenda/detail/349324

https://www.imooc.com/wenda/detail/336606

https://www.imooc.com/wenda/detail/347626

https://www.imooc.com/wenda/detail/346719

https://www.imooc.com/wenda/detail/346414

https://www.imooc.com/wenda/detail/350688

https://www.imooc.com/wenda/detail/355879

https://www.imooc.com/wenda/detail/337411

https://www.imooc.com/wenda/detail/336290

https://www.imooc.com/wenda/detail/355830

https://www.imooc.com/wenda/detail/355757

https://www.imooc.com/wenda/detail/336255

https://www.imooc.com/wenda/detail/336217

https://www.imooc.com/wenda/detail/345581

https://www.imooc.com/wenda/detail/356087

https://www.imooc.com/wenda/detail/331949

查看完整回答
反对 回复 2021-11-18
?
淡丁

TA贡献11条经验 获得超4个赞

A[1]是个数组里面有一个数据   a=123是你定义的一个数 这两个不能直接等 你把a=123删掉也是一样的效果

查看完整回答
反对 回复 2017-02-20
?
一条小咸鱼

TA贡献504条经验 获得超535个赞

肯定是0阿,你又没初始化数组


A[1] = a;


完全不知道你想问什么?

查看完整回答
反对 回复 2017-02-20

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信