值传递:
1 public class Demo01 { 2 public static void main(String[] args) { 3 int a=10; 4 System.out.println(a); 5 Demo01.change1(a); //调用函数改变a的值结果仍然不变 6 System.out.println(a); 7 } 8 public static void change1(int a){ 9 a=1; 10 } 11 }
引用传递:
1 public class Demo01 { 2 public static void main(String[] args) { 3 Person person =new Person(); 4 System.out.println(person.name); 5 Demo01.change(person); 6 System.out.println(person.name); 7 } 8 public static void change(Person person){ 9 person.name="zhaolei"; 10 } 11 } 12 13 class Person{ 14 String name; 15 }
标签:JAVA,void,System,基础知识,传递,person,static,public,out From: https://www.cnblogs.com/ZLey/p/16969409.html