错误:Implicit super constructor xx() is undefined for default constructor.
2014-10-31 21:46
393 查看
错误:Implicit super constructor xx() is undefined for default constructor. Must define an explicit constructor
因为你的父类已经定义了一个有参的构造函数并且父类中没有默认的无参构造方法,此时编译器不会为你调用默认的构造函数,
当子类继承时,必须在自己的构造函数显式调用父类的构造函数,自己才能确保子类在初始化前父类会被实例化,
如果你父类中有无参的构造函数,子类就不会强制要求调用,即你写的那个就可以通过,
编译器会默认帮你调用父类的构造函数。
按原来的思路,必须该成下面的:
class Person { protected String name; protected int age; //你已经定义了自动的构造函数,此时编译器不会为你创建默认的构造函数 public Person(String name,int age) { this.name=name; this.age=age; } public void print() { System.out.println("Name:"+name+"/nAge:"+age); } } /*由于父类的构造函数是有参的,所以编译不会为你自动调用默认的构造函数,此时,子类在自己的构造函数中必须显式的调用父类的构造函数 */ class Student extends Person { public Student(){ //子类构造函数 //super(); 不行,因为你的父类没有无参的构造函数 super("a",1); //显示调用父类的构造函数,而且必须是第一行调用 } } class Test { public static void main(String args[]){ } }
相关文章推荐
- 错误:Implicit super constructor Fu() is undefined for default constructor. Must define an explicit con
- Implicit super constructor xx() is undefined for default constructor. Must define an explicit constr
- Implicit super constructor xx() is undefined for default constructor. Must define an explicit constr
- Implicit super constructor xx() is undefined for default constructor. Must define an explicit constructor
- Implicit super constructor xx() is undefined for default constructor
- Implicit super constructor xx() is undefined for default constructor. Must define an explicit constr
- Implicit super constructor Object is undefined for default constructor. Must define an explicit cons
- Java error: Implicit super constructor is undefined for default constructor
- Implicit super constructor Object() is undefined for default constructor. Must define an explicit co
- Implicit super constructor Object() is undefined for default constructor. Must define an explicit co
- Implicit super constructor SimpleJavaFileObject() is undefined for default const
- error:Implicit super constructor Object() is undefined for default constructor..的解决方法
- Implicit super constructor Object() is undefined for default constructor. Must define an explicit c
- 错误:Implicit super constructor Father() is undefined. Must explicitly invoke another constructor
- 关于Implicit super constructor FF() is undefined. Must explicitly invoke another constructor
- Implicit super constructor BaseService() is undefined. Must explicitly invoke another constructor
- wsdl2java : The attribute required is undefined for the annotation type XmlElementRef+super构造函数函数错误.
- [Warning] TIMESTAMP with implicit DEFAULT value is deprecated.explicit_defaults_for_timestamp
- xib自定义UIView报错误 "forUndefinedKey:]: this class is not key value coding-compliant for the key"
- 错误:push.default is unset; its implicit 的解决