Error: Implicit super constructor XX () is undefined for default constructor. Must define an explicit constructor
Because your
parent class has defined a constructor with a parameter and there is no default parameterless constructor in the parent class , the compiler will not invoke the default constructor for you at this time, and when the subclass inherits, you must explicitly call the constructor
of the parent class in its own constructor to Make sure that the parent class is instantiated before initialization , and if you
have parameterless constructors in your parent class , the subclass will not force a call, that is, the one you write can pass, and the compiler will help you invoke the constructor of the parent class by default. According to the original idea, must be the following:
Class Person {
protected String name;
protected int age;
You have defined an automatic constructor, at which point the compiler will not create a default constructor for you
(String name,int age) {
this.name=name;
this.age=age;
}
public void print () {
System.out.println ("Name:" +name+ "/nage:" +age);
}
/* Because the constructor of the parent class is a parameter, the compilation does not automatically call the default constructor for you, at which point the subclass must explicitly call the constructor of the parent class in its own constructor/class
Student extends person {public
Student () { //Subclass Constructor
//super (); No, because your parent class has no parameterless constructor
super ("a", 1);
Displays the constructor that invokes the parent class, and must be the first line of call
}
class Test {public
static void Main (String args[]
)