62,628
社区成员
发帖
与我相关
我的任务
分享
public class ExecutionSque {
/**
* static变量,成员变量,构造方法,static代码块,构造代码块
*/
{
a=11;
System.out.println("构造快"+(a=12));
}
int a;
public static void main(String[] args) {
// TODO Auto-generated method stub
new ExecutionSque();
}
}
System.out.println的时候a还没有,你使用赋值,它会去找,System.out.println(a)也不行呀
/**
* static变量,成员变量,构造方法,static代码块,构造代码块
*/
int a;
{
a=11;
System.out.println("构造快"+a);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Test08();
}public class ExecutionSque {
{
String str;
str = "构造快" + a;//Cannot reference a field before it is defined 你还没有初始化这个变量无法操作!
str = "构造快" + c;//c cannot be resolved to a variable 你没定义这个变量,我用不了!
str = "构造快" + this.a;//这句没报错,为什么呢?因为this.a把a初始化为0了。
System.out.println(str);
}
int a;
public static void main(String[] args) {
new ExecutionSque();
}
}