One.
The public of the method in the inner inner class must carry, or the compilation will fail? are the permissions of the subclass greater than the permissions of the parent class ?
The above is a common form. Next, simplify the anonymous inner class.
According to the anonymous inner class that we discussed earlier, it is difficult to write in multiple methods.
What do we do now to make multiple method calls to an object? Just name it and borrow your previous experience.
Give it a name, by the type of the parent class, not the subclass or the inner class, which is still an anonymous inner class. This is also the use of polymorphism.
This is what we call the basic application of anonymous internal classes.
The application scenario for anonymous inner classes is this:
Not more than three, is said one or two. Passed? Passed as a parameter?
For example, below the main function, there is a inter type of interface reference,
It is common practice to create a class implementation interface before creating an object of the class. The question is, why does the function actually use an interface as an argument ?
But then we think that defining a class is a hassle and it can be simplified,
Why not emphasize more than three? Because the method is particularly long, it means that the anonymous inner class method body content is more, this object is too fat, reading is not.
Simplification is for reading, so it goes against the original intention.
This example is not an internal class, but the format of the anonymous inner class is wrong, and the class that implements the interface is actually an inner class.
Java-Preliminary Understanding-tenth-Anonymous inner class-application