class A {
private int x;
public static void main(String args[]){
new B();
} class B{
B(){
System.out.println(x);
}
}
}
这个错在哪里?
放到eclipse里,显示的英文错误,我看不懂
private int x;
public static void main(String args[]){
new B();
} class B{
B(){
System.out.println(x);
}
}
}
这个错在哪里?
放到eclipse里,显示的英文错误,我看不懂
所以new B();
显然在一个静态方法里不成功。
class A {
private int x;
public static void main(String args[]){
new A().new B();
} class B{
B(){
System.out.println(x);
}
}
}
你调用内部类得先生成外部类的对象
或者用静态内部类class A {
private static int x;
public static void main(String args[]){
new B();
} static class B{
B(){
System.out.println(x);
}
}
}
private static int x;
public static void main(String args[]){
new B();
} static class B{
B(){
System.out.println(x);
}
}
}
哈哈
如果是静态内部类应该是 new A.B();
static是new A.B();不过既然定义成内部类 也就没有被外部访问的意义
我是这样认为的! 呵呵
new B();修改为new A().new B();