14. Internal classes and anonymous classes

Source: Internet
Author: User

1. DefinitionA class is defined inside another class.   Compiled out are the outer class $ inner class. class. Inner classes are free to use member variables, functions in external classes.
2. How to useThe object that generated the inner class.   A.B B = new A (). New B ();   A is an outer class and B is an inner class.   Calling the member variable of the inner class, direct J, is equivalent to THIS.J calling the member variable of the external class, A.THIS.I initializes the inner class from the program code of the external class, and the inner object is bound to the external object.   The program code for an external class can initialize the inner classes it contains by initializing the other class in exactly the same way. With an internal class, you can implement for example: When two buttons perform different tasks, how to get events on two different buttons respectively.   This means that the same interface can be implemented in different ways. Internal classes are very convenient for listening to events. Because the same event handlers can be implemented separately for more than one time. 3. How to use anonymous internal classesNew interface, followed by a class implementation result after the interface. It has no name B.fun (new A (){public void DoSomething (){System.out.println ("dosomething");}});



From for notes (Wiz)

14. Internal classes and anonymous classes

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.