答案:t1.level=9
t2.level=47
t1.level=47
t2.level=47
t1.level=27
t2.level=27- class Tank{
- int level;
- }
- public class Cs {
- public static void main(String [] args)
- {
- Tank t1=new Tank();
- Tank t2=new Tank();
- t1.level = 9;
- t2.level =47;
- System.out.println("t1.level="+t1.level);
- System.out.println("t2.level="+t2.level);
- t1=t2; //t1,t2指向同一个对象
- System.out.println("t1.level="+t1.level);
- System.out.println("t2.level="+t2.level);
- t1.level =27; //因为之前t1,t2指向了同一个对象,所以输出值都是27
- System.out.println("t1.level="+t1.level);
- System.out.println("t2.level="+t2.level);
- }
- }
复制代码 |