ValueTest1.java
package com.sxt.valuetest; /* * 基本数据类型的传递:传递的是值得副本 */ public class ValueTest1 { public static void main(String[] args) { int num = 10; System.out.println("方法调用前:"+num);//10 changeValue(num); System.out.println("方法调用后:"+num);//10 } private static void changeValue(int num) { num = 20; System.out.println("方法调用中:"+num);//20 } }
ValueTest2.java
package com.sxt.valuetest; /* * 基本数据类型的传递:地址 */ public class ValueTest2 { public static void main(String[] args) { String s = "范冰冰"; System.out.println("方法调用前:"+s);//范冰冰 changeValue(s); System.out.println("方法调用后:"+s);//范冰冰 } private static void changeValue(String s) { s = "Angelababy"; System.out.println("方法调用中:"+s);//Angelababy } }