【发布时间】:2018-01-13 08:46:37
【问题描述】:
为什么在类 Test01 中的 if 语句之后 b 为真 - 而在类 Test02 中的 else if 语句之后 b 似乎不是是真的吗?
/* Evaluate the two classes below independently of one another*/
class Test01 {
public static void main(String[] args){
boolean b = true;
if (b)
System.out.println("B");
}
}
class Test02 {
public static void main(String[] args){
boolean b = true;
if (b = false)
System.out.println("A");
else if (b)
System.out.println("B");
}
}
【问题讨论】:
-
打开你的编译器警告,你会得到答案。
-
你正在评估价值而不是评估