No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing 问题解释
2014-08-05 10:56
441 查看
public class Superclassquote {
class Father{
String a = "Father";
public String print(){
return "I am the father";
}
}
class son extends Father{
String a = "son";
public son(){}
public String print(){
return "I am the son";
}
}
public static void main(String[] args){
Father a = new son();//在这里出现了错误
}
}
翻译的话是:没有可访问的内部类E的实例,必须分配一个合适的内部类E的实例(如x.new A(),x必须是E的实例。)
内部类是动态的,也就是开头以public class开头。而主程序是public static class main。
在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。
所以[b]在不做其他变动的情况下,最简单的解决办法是将public class改为public static
class.
[/b]
class Father{
String a = "Father";
public String print(){
return "I am the father";
}
}
class son extends Father{
String a = "son";
public son(){}
public String print(){
return "I am the son";
}
}
public static void main(String[] args){
Father a = new son();//在这里出现了错误
}
}
翻译的话是:没有可访问的内部类E的实例,必须分配一个合适的内部类E的实例(如x.new A(),x必须是E的实例。)
内部类是动态的,也就是开头以public class开头。而主程序是public static class main。
在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。
所以[b]在不做其他变动的情况下,最简单的解决办法是将public class改为public static
class.
[/b]
相关文章推荐
- 内部类的使用问题No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclo
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleT
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosi
- No enclosing instance of type A is accessible. Must qualify the allocation with an enclosin
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleT
- java中No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosi
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- No enclosing instance of type B is accessible. Must qualify the allocation with an enclosing ins (20
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- <java>No enclosing instance of type GraphicFrame is accessible. Must qualify the allocation with an
- - No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing in
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing