A Discussion on Java anonymous classes and internal classes

Source: Internet
Author: User
Basic Theory:
-----------------------------------------------------
Java internal class: the definition of an internal class is defined within another class.

The reason is:

1. An internal class object can access the implementation of the object created for it, including private data. That is, an internal class instance is privileged to the instance of the class that contains it.

2. for other classes in the same package, the internal class can be hidden. In other words, the internal class, regardless of the method visibility, may be public. In addition to the inclusive class, other classes cannot use it.

3. Anonymous internal classes can easily define callbacks.

4. Use internal classes to easily write event-drivenProgram.

In fact, it is only intended to define callback-further, it is event-driven.

Interface and callback: a common programming mode is the callback mode. In this mode, you can specify the method of the callback object when a specific time occurs.

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.