Let me share with you the inheritance of the internal class of Java through the example code. The details are as follows:
The constructor of the Java internal class must be connected to a reference to its peripheral object (the internal class must give it a reference to an external class object, and the internal class depends on the external class object). Therefore Manually add the call of the base constructor in the constructor of the class.
Because when the export class is instantiated, there is no peripheral object, so that the export -class instance is connected to it.
Therefore, we need to create a peripheral class, and then use a specific syntax to show the relationship between the internal class and the peripheral class.
In the following example, a reference to the export class Inheritinner from the peripheral class in the internal class needs to be given. Ordinary inheritance only needs to add super () to the exported constructor;, the internal class needs to reference the peripheral class object .super ();
class withInner {class inner {}} Public Class Inheritinner Extends Withinner.Inner {Inheritinner (Withinener Wi) {wi.super (); // Wi's parent class is Object} static void main (string [] args) {withInner Wi = New Withinner (); Inheritinner II = New Inheritinner (wi);}}
And further, what should I do when the inherited internal class is only a non -default constructor?
class withInner {Class Inner {Public Inner (int i) {System.out.println (I);}} Public Class Inheritinner withIntenner.Inner {Inheritinner (Withritinner Ner wi) {int i = 0; wi.super (i) // As shown in the code, when the inherited constructor needs parameters, the parameters should be passed to this super function} Public Static Void Main (string [] args) {withInner wi = new withInner (); Inheritinner II = New Inheritinner (wi);}}
The above is a detailed explanation of the inheritance of the Java internal class, I hope to help everyone.