引用数据类型的传递,那个值先输出,后面的也同样是同一个值

public class TestReferenceType {
public static void main(String[] args) {
Student student = new Student();
student.id = 2000;
method(student);
System.out.println("main:" + student.id);//2000
}

// 引用数据类型直接传类和引用变量
public static void method(Student student) {
student.id = 1000;
System.out.println(student.id);//1000
}
}

结果:

1000
main:1000

猜你喜欢

转载自www.cnblogs.com/Koma-vv/p/9503248.html