曾经以为百般艰难,蓦然回首,才发现已飞渡千山。。!
楼上的似乎没有理解我的意思。请看如下程序:
public class BooleanTest
{
public static void main(String[] args)
{
int a = 20;
int b = 30;
boolean x, y,z;
x = (a > b);
y = (a < b);
z = ((a + b) == 50);
System.out.println("x=" + x);
System.out.println("y=" + y);
System.out.println("z=" + z);
}
}
如果我把
x = (a > b);
y = (a < b);
z = ((a + b) == 50);
删去,则运行时出现:
BooleanTest.java:12: variable x might not have been initialized
System.out.println("x=" + x);
^
BooleanTest.java:13: variable y might not have been initialized
System.out.println("y=" + y);
^
BooleanTest.java:14: variable z might not have been initialized
System.out.println("z=" + z);
^
3 errors
也就是说没有对x,y,z进行初始化。所以我的意思是是否
x = (a > b);
y = (a < b);
z = ((a + b) == 50);
也算作初始化?还有没有除了这种方法和直接赋初值之外的其他初始化方法?
谢谢。