Knowledge about Java internal classes

Source: Internet
Author: User

1. Internal classes can be static, protect, and private, but external classes containing internal classes can only use public and default package access permissions.

2. The internal class can access the content of the external class object that creates it, and even include the private variable.

3. classification of internal classes ● Member internal classes (an internal class exists as a member of an external class, and is in parallel with the external class methods and attributes .) outer. inner inner = outer. new inner (); // in this way, new inner outer is an external Class Object

● Local internal class (the internal class defined in the method is called a local internal class. it is similar to a local variable, so the local internal class cannot have an access modifier, because it is not an external class member, but it can access the constants of the code block in the current method, and all external class members .) new inner (). tostring (); // note that the internal class method is called in this way

● Static internal class (nested class) (the internal class exists as a member of the external class and is in parallel with the method and attribute of the external class, but is modified using static, you cannot access non-static external class objects through static internal class objects.) Inner inner = new inner (); // an internal class object is generated here and you no longer need to access external class objects.

● Anonymous internal class (an anonymous internal class is a class without a name. The new statement is followed by the class Rewriting Method)

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.