当前位置: 技术问答>java相关
什么是inner class?类不过不加修饰符,它的访问权限是protected or default?
来源: 互联网 发布时间:2015-08-30
本文导语: 不好意思,很无知的问题。 | public class Outer1 { private int size; /* Declare an inner class called "Inner" */ public class Inner { public void doStuff() { // The inner class has access to ’size’ fro...
不好意思,很无知的问题。
|
public class Outer1 {
private int size;
/* Declare an inner class called "Inner" */
public class Inner {
public void doStuff() {
// The inner class has access to ’size’ from Outer
size++;
}
}
public void testTheInner() {
Inner i = new Inner();
i.doStuff();
}
}
这是SUN的例子
private int size;
/* Declare an inner class called "Inner" */
public class Inner {
public void doStuff() {
// The inner class has access to ’size’ from Outer
size++;
}
}
public void testTheInner() {
Inner i = new Inner();
i.doStuff();
}
}
这是SUN的例子
|
应该是这样的:
Modifier Same Class Subclass Same Package Universe
public Yes Yes Yes Yes
protected Yes Yes Yes
private protected Yes Yes
private Yes
Modifier Same Class Subclass Same Package Universe
public Yes Yes Yes Yes
protected Yes Yes Yes
private protected Yes Yes
private Yes
|
看看Think in Java 里面的关于内部类的讲解,保证让你受益非浅
|
protected
|
就是CLASS里面再建一个class,那里面的class就是inner class了