Inheritance of Java internal classes (all)

Let's share the inheritance of Java internal classes through the example code. The details are as follows:

The constructor of the Java internal class must be connected to the reference to its peripheral class object (the constructor of the internal class must give it a reference to the external class object, and the internal class depends on the external class object). Therefore, when inheriting the internal class, you need to manually add a call to the base class constructor in the constructor of the exported class.

Because when the exported class is instantiated, there is no peripheral class object to connect the instance of the exported class to it.

Therefore, we need to create a peripheral class, and then use a specific syntax to indicate the relationship between the inner class and the peripheral class.

In the following example, you need to give the exported class inheritinner a reference from the outer class of the inner class. For ordinary inheritance, you only need to add super(); in the exported class constructor;, The inner class needs the outer class object reference super();

Further, what should I do when the inherited inner class has only a non default constructor?

The above is a detailed explanation of the inheritance of Java internal classes. I hope it can help you.

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
分享
二维码
< <上一篇
下一篇>>