package com.wjk.test;
class Tank {
int level;
}
public class Assignment {
public static void testTank() {
Tank t1 = new Tank();
Tank t2 = new Tank();
t1.level = 9;
t2.level = 47;
System.out.println("t1.level="+t1.level+",t2.level="+t2.level);
//t1.level=9,t2.level=47
t1=t2;
System.out.println("t1.level="+t1.level+",t2.level="+t2.level);
//t1.level=47,t2.level=47
t1.level = 27;
//修改的是堆内存中的对象 t1,t2都是堆内存中对象的引用,t1,t2指向同一个堆内存
//之前一直以为修改的是栈内存中对象的引用
System.out.println("t1.level="+t1.level+",t2.level="+t2.level);
//t1.level=27,t2.level=27
}
public static void main(String[] args) {
testTank();
}
}
class Tank {
int level;
}
public class Assignment {
public static void testTank() {
Tank t1 = new Tank();
Tank t2 = new Tank();
t1.level = 9;
t2.level = 47;
System.out.println("t1.level="+t1.level+",t2.level="+t2.level);
//t1.level=9,t2.level=47
t1=t2;
System.out.println("t1.level="+t1.level+",t2.level="+t2.level);
//t1.level=47,t2.level=47
t1.level = 27;
//修改的是堆内存中的对象 t1,t2都是堆内存中对象的引用,t1,t2指向同一个堆内存
//之前一直以为修改的是栈内存中对象的引用
System.out.println("t1.level="+t1.level+",t2.level="+t2.level);
//t1.level=27,t2.level=27
}
public static void main(String[] args) {
testTank();
}
}