Java中的数据类型可以分为两大类:基本数据类型与引用数据类型,现关于两种数据类型的赋值做一个示例。
public class ValueTransferTest {
public static void main(String[] args) {
System.out.println("---------基本数据类型---------");
int m = 10;
int n = m;
System.out.println("m = " + m + ",n = " + n);
n = 20;
System.out.println("m = " + m + ",n = " + n);
System.out.println("---------引用数据类型---------");
Student stu = new Student();
stu.age = 10;
Student stu2 = stu;
System.out.println("stu.age =" + stu.age + ",stu2.age =" + stu2.age);
stu2.age = 20;
System.out.println("stu.age =" + stu.age + ",stu2.age =" + stu2.age);
}
}
class Student{
Integer age;
}
控制台显示结果
---------基本数据类型---------
m = 10,n = 10
m = 10,n = 20
---------引用数据类型---------
stu.age =10,stu2.age =10
stu.age =20,stu2.age =20