Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误--使用Java 8的Eclipse中的超类构造函数_Java_Eclipse_Inheritance_Java 8_Super - Fatal编程技术网

错误--使用Java 8的Eclipse中的超类构造函数

错误--使用Java 8的Eclipse中的超类构造函数,java,eclipse,inheritance,java-8,super,Java,Eclipse,Inheritance,Java 8,Super,我在eclipse中编写代码,并且是java新手,继承了方法,并使用super()关键字调用父方法,显示java-8中的错误以及new Child()方法也显示错误。文件名为Example.java public class Example{ class Parent{ void parentMethod(){ System.out.println("Parent Method"); }

我在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).
。 ; .

  • super(10)只能在构造函数内部(而不是在方法内部)用于调用超类(被扩展的类)的构造函数,例如,如果您有
    Parent(int a){…}
    ,则可以执行
    Child(){super(10);}
    ;或者,如果要调用超类的现有方法(而不是带有单个数字参数的不存在的超级构造函数),请使用
    super.parentMethod(10)取而代之
  • 新建子项()
    在非
    静态
    嵌套类的
    静态
    方法中不起作用;非静态内部类属于外部类的实例:
    newexample().newchild()将在这里工作;或者,由于在示例中嵌套的类不使用
    example
    的实例方法和字段,因此可以使类
    Parent
    Child
    静态以修复错误:
    静态类Parent{
    静态类Child扩展Parent{

这不是如何声明公共类
公共类父类
公共类子类扩展父类
仍然会出错为什么您首先要使用内部类?目的是什么?您想用
super(10);
做什么?