And look back on the tenth day of Java

Source: Internet
Author: User

Inner class

Most of the time, we define the class as a separate program unit. In some cases, we need to place a class within the definition of another class, which is defined inside other classes as inner classes (nested classes), and classes containing inner classes are called external classes (host classes). The inner class has the following functions

  • The inner class provides a better encapsulation that hides the inner class within the outer class and does not allow access to other classes of the same package. Suppose you create the Cow class, you need to combine the properties ofthe cowleg ,cowleg property is valid only in the Cow class, leaving the Cow class is meaningless, in which case the Cowleg can be defined as an inner class of Cow, and no other external classes are allowed to access
  • Inner class members have direct access to private data inside the outside because the inner class is treated as a member of its outer class and can be accessed between members of the same class. However, the implementation details of the inner class, such as properties, cannot be accessed externally. To access an object that must create an inner class.
  • Anonymous inner classes are appropriate to create classes that only need to be used once

And look back on the tenth day of Java

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.