日期:2014-05-20  浏览次数:20798 次

闲来无事写的东西,结果自己有点看不懂了,大家一起来看看吧
代码如下:
public class ClassTest {
String tem = " ";
Object temp = (this.temp == " "?" ":0);
Object ten = (this.tem == " "?" ":0);
Object tep = (this.temp == " "?" ":0);
public ClassTest(String temp){
this.temp = temp;
}
public static void main(String[] args){
ClassTest tr = new ClassTest(" ");
ClassTest td = new ClassTest("2");
System.out.println("---"+tr.ten+"---"+td.ten);
System.out.println("---"+tr.tep+"---"+td.tep);
}
}
运行结果:
--- --- 
---0---0


------解决方案--------------------
探讨
String tem = " ";
Object temp = (this.temp == " "?" ":0);
Object ten = (this.tem == " "?" ":0);
Object tep = (this.temp == " "?" ":0);

这此语句都在new ClassTest("2");之前执行了,

所以tem temp ten tep的值都不会因……

------解决方案--------------------
无论new的参是什么
ten tep的值都是恒定为"" 和 0

------解决方案--------------------
哪里看不懂,一个类..有构造函数
------解决方案--------------------
探讨

String tem = " ";
Object temp = (this.temp == " "?" ":0);
Object ten = (this.tem == " "?" ":0);
Object tep = (this.temp == " "?" ":0);

这此语句都在new ClassTest("2");之前执行了,

所以tem temp ten tep的值都不会……