The constructor of the Java inner class must be connected to a reference to its perimeter class object (the constructed inner class must give it a reference to an outer class object, the inner class depends on the Outer class object), so when inheriting the inner class, you need to manually include the call to the base class constructor in the constructor of the exported class.
Because, when you export a class instantiation, there is no perimeter class object to allow an instance of the exported class to connect to it.
So, we need to create a perimeter class and then use a specific syntax to indicate the relationship between the inner class and the outer class.
In the following example, the export class needs to be inheritinner a reference from a perimeter class in the inner class. Ordinary inheritance, you simply add super () to the export class constructor, and the inner class requires a perimeter class object reference. Super ();
1 Class withinner{2 class inner{} 3} 4 public class Inheritinner extends withinner.inner{5 inheritinner (Withinn Er wi) {6 wi.super ();//wi's parent class is Object 7 } 8 public static void Main (string[] args) {9 Withinner WI = new Withinner (); Inheritinner II = new Inheritinner (WI); }12}
and further, what should be done when the inherited inner class has only a non-default constructor?
Class withinner{ class inner{public Inner (int i) { System.out.println (i);}} } public class Inheritinner extends withinner.inner{ inheritinner (Withinner wi) { int i=0; Wi.super (i);//As shown in the code, arguments should be passed to this super function when the inherited constructor requires arguments {public static void Main (string[] args) { Withinner WI = new Withinner (); Inheritinner II = new Inheritinner (WI);} }
Inheritance of Java inner classes