Java Inner class: Anonymous inner Class (iv)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.