+ -
当前位置:首页 → 问答吧 → 内部类访问外部类的成员变量,谁能解释一下

内部类访问外部类的成员变量,谁能解释一下

时间:2011-12-09

来源:互联网

public class PrivateConstructor {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
A a = new A(1);
a.getB().print();
}

}

class A{
int a;

private A(){}

public A(int a){
this.a=a;
}

class B extends A{

int b;

void print(){

System.out.println("B in A " + a);

System.out.println("B in A " + A.this.a);
}
}

B getB(){
return new B();
}


}



B in A 0
B in A 1

第一个访问的a为什么是0,难道内部类就把这个a当做一个普通变量吗?

作者: promzaid   发布时间: 2011-12-09

mark..明天来看解释

作者: CherryMs   发布时间: 2011-12-10

热门下载

更多