值传递和引用传递的区别和理解demo
来源:互联网 发布:excel数据相关性分析 编辑:程序博客网 时间:2024/06/05 15:24
package test1;public class Father {protected final int adds(int a,int b) {return a+b;}private static int day;private static int month;private static int year;/** * 值传递,参数为基本类型 */public static void display(int year,int month,int day) {day=11;month=11;year=2015;System.out.println("传递方法中:"+year+"-"+month+"-"+day);}/** * 引用传递,传递的是引用类型 * @param father */public void display(Father father) {father.day=11;father.month=12;father.year=2014;System.out.println("传递方法中:"+father.year+"-"+father.month+"-"+father.day);}/** * * 值传递测试 */public static void testValue1() {Father father = new Father();int day =12,month=12,year=2016;System.out.println("传递之前:"+year+"-"+month+"-"+day);father.display(year,month,day);System.out.println("传递之后:"+year+"-"+month+"-"+day);}/** * 引用传递测试 */public static void testValue2() {Father father = new Father();father.day = 3;father.month= 3;father.year =2016;System.out.println("传递之前:"+father.year+"-"+father.month+"-"+father.day);father.display(father);//传递之后,再打印father对象的值System.out.println("传递之后"+father.year+"-"+father.month+"-"+father.day);}public static void main(String[] args) {testValue1();testValue2();}}
阅读全文
0 0
- 值传递和引用传递的区别和理解demo
- 引用传递和值传递的区别
- 值传递和引用传递的区别
- 值传递和引用传递的区别
- 值传递和引用传递的区别
- 值传递和引用传递的区别
- 值传递和引用传递的区别
- 值传递和引用传递的区别
- 值传递和引用传递的区别
- 引用传递和值传递的区别
- 值传递、指针传递和引用传递的区别
- 【java】值传递和引用传递理解
- 深入理解值传递和引用传递
- "栈"和"堆"的区别; 引用传递和值传递
- 对于值传递和引用传递的理解
- java新手对于值传递和引用传递的理解
- 让你更好的理解 引用传递 和值传递
- 对java值传递和引用传递的一些理解
- Android Studio 提示Session 'app':Error Installing APK
- 前端涉及的所有知识体系
- openssl c++实现bouncycastle中AES加解密
- css+js制作简单的轮播图效果
- Javascript学习笔记(Object 对象与继承)
- 值传递和引用传递的区别和理解demo
- android viewpager 竖屏滑动效果
- Markdown系列(5)- Markdown书写建议
- 产品策划七:App界面交互设计规范
- leetcode_403. Frog Jump ? 待解决
- open live 2.0 导入报错Unable to merge dex
- Mysql中的数据类型对应Java中什么数据类型
- Adobe Acrobat DC Prof
- 动画:平移旋转布赛尔曲线动画