Below through the example code to share with you about the Java internal classes of inheritance, specific details are as follows:
The constructor of the Java inner class must be connected to a reference to its Outer class object (the constructed inner class must give it a reference to an external class object). An inner class relies on an external class object, so it is necessary to manually add a call to the base class constructor in the constructor of the exported class when inheriting the inner class.
Because, when you export a class instantiation, there is no outer-class object that allows an instance of the exported class to be connected to it.
So, we need to create a perimeter class and then use a specific syntax to show the relationship between the inner class and the outer class.
In the following example, you need to inheritinner a reference from the outer class of the inner class to the derived class. Ordinary inheritance, you simply add super () to the export class constructor, and the inner class requires a peripheral class object reference. Super ();
Class withinner{
class inner{}
} public
class Inheritinner extends withinner.inner{
Inheritinner ( Withinner WI) {
wi.super ();//wi parent class is Object
} public
static void Main (string[] args) {
Withinner WI = new Withinner ();
Inheritinner II = new Inheritinner (WI);
}
And further, what happens when an 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, when the inherited constructor requires parameters, pass the parameter to this super function} public
static void Main (string[] args) {
Withinner WI = new Withinner ();
Inheritinner II = new Inheritinner (WI);
}
The above is the Java internal class inheritance detailed, hope to be able to help everybody.