【发布时间】:2014-04-02 17:57:55
【问题描述】:
我研究 java 内部类。
我写了例子:
public class Outer {
public Outer(int a){}
public class Inner {
public Inner(String str, Boolean b){}
}
public static class Nested extends Inner{
public static void m(){
System.out.println("hello");
}
public Nested(String str, Boolean b , Number nm) { super("2",true); }
}
public class InnerTest extends Nested{
public InnerTest(){ super("str",true,12); }
}
}
我使用以下字符串从 main 调用它:
new Outer(1).new Inner("",true);
我看到编译错误:
java: no enclosing instance of type testInheritancefromInner.Outer is in scope
你能解释一下这种情况吗?
更新
【问题讨论】:
-
请贴出完整代码。
-
这是什么
testInheritancefromInner?
标签: java inheritance instantiation inner-classes