As a question: New A subclass that has no constructor method invokes the parameterless constructor method of the parent class. Like the following two classes:
public class Fatherclass {
private int age;
Public fatherclass (int age) {
super ();
SYSTEM.OUT.PRINTLN ("Initialization value" + age);
}
Public Fatherclass () {
System.out.println ("Fathercalss");
}
public class Subclass extends Fatherclass {
int A;
Boolean flag;
String str;
}
public class Test {public
static void Main (string[] args) {
Subclass subclass = new Subclass ();
System.out.println (SUBCLASS.A);
System.out.println (Subclass.flag);
System.out.println (SUBCLASS.STR);
Subclass.tostring ();
}
The above three classes are parent, subclass, and test class respectively. The output results are as follows:
FATHERCALSS
0
false
null
As you can see from the results, when a subclass does not define an parameterless construction method, the new object of that class invokes the parameterless construction method of its parent class. Also, the parameters in the subclass are initialized, and the int type is initialized to the 0,boolean type, initialized to False, and the referenced object is initialized to null.