基本数据类型与引用数据类型传递
2015-11-24 17:21
239 查看
基本数据类型:传递的是 值 本身—栈中操作
引用数据类型: 应用,不是 值 本身 —堆中操作(可修改)
Demo1:
Demo2:
引用数据类型: 应用,不是 值 本身 —堆中操作(可修改)
Demo1:
public class PassValue{ public static void main(String[] args){ PassValue pv = new PassValue(); int x = 5; System.out.println("方法调用之前x==" + x);//5 pv.change(x);//100 System.out.println("方法调用之后x==" + x);//5 } public void change(int y){//y = 5; y = 100; System.out.println("方法中y==" + y);//100 } }
Demo2:
public class PassValue2{ private int x ; public static void main(String[] args){ PassValue2 obj = new PassValue2(); obj.x = 5; System.out.println("方法调用之前obj.x==" + obj.x);//5 obj.change(obj);//100 System.out.println("方法调用之后obj.x==" + obj.x);//100 } public void change(PassValue2 obj2){ obj2.x = 100; System.out.println("方法中obj2.x==" + obj2.x);//100 } }
相关文章推荐
- QT Design Form 积累
- android studio 获取 sha1,md5 for mac
- C语言 HTTP上传文件-利用libcurl库上传文件。
- Rabbimq几个关键参数对性能的影响
- c和C++main函数中参数的意义和用法
- es _bulk批处理
- 不通过app Store,使用Ad Hoc发布应用程序
- Javascript模块化编程(三):require.js的用法
- Android数据存储五种方式总结<转载>
- Android PopupWindow的使用
- M3: 将页面元素制作为图片
- 老李分享:网页爬虫java实现
- Derby-10.11学习笔记(二)脚本介绍
- 成员变量与局部变量
- 安全问题
- cocos2dx-JS 多行多列TableView
- arcmap发布不了feature access 服务
- 毕业生自传-11(入职何乐喜)
- 图像处理(二)
- CriminalIntent项目开发笔记(二)