Package Com.minimax.demo;
public class Superclass {
Public superclass () {System.out.println ("parent class no parameter construction method");} Public superclass (String name) {System.out.println ("parent class has a parameter constructor method");}} Package Com.minimax.demo;public class Subclass extends superclass{/** * @param args */public static void main (string[] Arg s) {//TODO auto-generated method stub subclass Sub=new subclass ("Jack"); Public subclass () {System.out.println ("subclass no parameter construction method");} Public subclass (String name) {//super (); super (name); System.out.println ("Sub-class has a method of constructor");}}
When creating subclass subclass, if you use a constructor method with a parameter, if super () is used in the constructor, the parameterless constructor method of the parent class is called, and if Super (name) is used, the parent class's argument constructor method is called, and if Super () is not used, The non-parametric constructor method of the parent class is called by default.
Java Subclass Object Generation