【发布时间】:2020-01-19 06:13:22
【问题描述】:
我在 Eclipse 和 Java 新手中编码,继承方法和调用父方法,super() 关键字在 Java-8 中显示错误,new Child(); 方法也显示错误。文件名为 Example.java
public class Example{
class Parent{
void parentMethod(){
System.out.println("Parent Method");
}
void parentMethod(int a){
System.out.println("Parent Method: One Argument");
}
void parentMethod(int a, int b){
System.out.println("Parent Method: Two Argument");
}
}
class Child extends Parent{
void childMethod() {
super(10);
System.out.println("Child Method");
}
}
public static void main(String[] args) {
new Child();
System.out.println("Main Class Method: no argument");
}
}
它在eclipse中给出了一个错误:
in line 15: Multiple markers at this line
- Line breakpoint:Public$Child [line: 15] -
childMethod()
in line 20: No enclosing instance of type Public is accessible. Must qualify the allocation with an enclosing
instance of type Public (e.g. x.new A() where x is an instance of Public).
。 ; .
【问题讨论】:
-
这不是你声明公共类的方式
public class Parent&public class Child extends Parent -
还是报错
-
你为什么首先使用内部类?什么目的?你想用
super(10);做什么?
标签: java eclipse inheritance java-8 super