Inheritance of Java person, student and goodstudent and execution of constructor

There are three classes: person, student and goodstudent. Among them, student inherits person and goodstudent inherits student. There is only the default constructor in the three classes. What method is used to prove whether the constructor of person is called when creating the object of student class and whether the constructor of student is called when creating the object of goodstudent class? If the person constructor is not called when creating the student object (I don't know under what circumstances it will not be called, if it is the default parameterless constructor), what means can be used to call the constructor of the parent class?

1、 Need analysis

1. Inheritance relationship of three classes: person and goodstudent 2. Implement constructors of three classes 3. Print information to see whether constructors of each class are called

2、 Technical point

1. Find out that the parameterless constructor of Java class is called by default. 2. If the constructor of the parent class has parameters, add super (args) in the first line of the constructor of the subclass; To confirm which parent constructor to call

code:

Call procedure of print constructor:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>