Introduction to Java programming tutorial--calling the parent class constructor

In inheritance, the subclass object must call the constructor in the parent class before instantiating, and then call its own constructor.
 

sample program

 

      Example program for subclass object instantiation. When a subclass object is instantiated, it will first call the constructor of the parent class, and then call its own constructor. So when instantiating a subclass object, you need to initialize the properties of the parent class first.  

Guess you like

Origin blog.csdn.net/u010764893/article/details/131140122