Http://blog.csdn.net/fhm727/article/details/5220003
1. What is an anonymous internal class?
An internal class exists in another class, while an anonymous internal class, as its name implies, is an internal class without a name.
2. Why do I need anonymous internal classes?
Each inner class can inherit an implementation class ). Therefore, inner class is not limited to whether the outer class has inherited from a certain implementation class.
If the capabilities provided by inner class "inherit from multiple concrete or abstract classes" are missing, some design and programming problems will become very tricky.
Therefore, from a certain perspective, inner class is a complete solution to multiple inheritance issues. Interface can solve some of these problems, but inner classes
In order to effectively and practically allow "multiple implementation )". That is to say, inner classes actually allows you to inherit multiple non-interfaces.
At this level, internal classes are generally instantiated and initialized through their parent classes or inherited interfaces, as shown in Figure 3. In this case, the internal class name (a) is redundant, therefore, the anonymous internal class is used.
3. How to Implement anonymous internal classes?
the implementation of anonymous internal classes is very simple, if there is an interface
interface a {public void method ();}
you can write the following statement to get the object of the implementation class of interface a
A = new A () {public void method () {system. out. println ("hehe") ;};
and {public void method () {system. out. PR Intln ("hehe") ;}}; defines an anonymous internal class
4. Answer we can see that an anonymous internal class must be implemented using one class or one interface. At this level, it can inherit other classes or implement interfaces, but it is impossible to use the extends or implements keyword..