Java Internal class summary

Source: Internet
Author: User


6.4 Internal Classes

    1. Concept: an inner class is a class that is defined in another class.

    2. Benefit: You can access all of the data for the class, including private Data.

      Inner classes are hidden from other classes of the same package.

I. Internal class Access Objects

    1. Inner and outer classes are relationships between classes, and not every external class has an instance domain of an inner class.

    2. An object in an inner class always has an implicit reference to the outer class object that created it

    3. Only inner classes can be private classes, whereas regular classes can only be package visibility or public visibility.

II. internal class rules

    1. Can be used outer.new Inner (...) To create an inner class

    2. All static domains declared by the inner class must be final, and the inner class cannot have a static method

    3. The compiler translates the inner class into the class Name: Outer$inner's general class

III. Classification of internal classes

    1. Local inner Class:

      1) The local inner class cannot be declared with public or private, and its scope is limited to the block of the local class.

      2) Advantages: The local method is completely hidden outside, not only access the external class, but also access to local variables, but those local variables must be final.

    2. Anonymous inner Class:

      1) Anonymous classes cannot have Parameters.

    3. Static inner Class:

      When: just to hide a class in another class, you do not need an object in which to reference the outer class.

      A static inner class is exactly the same as all other inner classes except that it does not generate a reference to an external class.

      Declaring inner classes automatically to static and public in an interface

This article is from the "red xiao" blog, please be sure to keep this source http://cnslp.blog.51cto.com/11387491/1918453

Java Internal class summary

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.