The Java inner class is divided into 4 sections, namely, overview, member inner class, local inner class, and anonymous inner class.
In this article, the anonymous inner class of the Java inner class is mainly about the concept of anonymous inner classes, the benefits of anonymous inner classes, the use of anonymous inner classes, and the application scenarios for anonymous inner classes.
1. The concept of anonymous inner class
A class without a class name is called an anonymous inner class
2. Benefits of Anonymous internal classes
Simplified writing
3, the use of anonymous internal class premise
There must be inheritance or implementation relationships to use
4. Application scenarios of anonymous internal classes
Anonymous inner classes are generally used for arguments
Example code:
Package Com.rk.innerclass;public class Myclasslearn{public static void Main (string[] args) {Runnable target = new Runnable () {public void run () {for (int i=0;i<10;i++) {System.out.println ("Hello world-" +i);}}; Thread thread = new thread (target); Thread.Start ();//thread.yield ();}}
In the preceding code, the target variable points to an object of an anonymous class that implements the Runnable interface and is passed to the thread's constructor as an argument.
5. Mind Mapping
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7F/04/wKiom1cPpTiRvOxCAAC1lMLBRUI706.png "title=" Java internal class. png "alt=" Wkiom1cpptirvoxcaac1lmlbrui706.png "/>
Java Inner class: Anonymous inner Class (iv)