Java Internal Classes

Source: Internet
Author: User

1. member Inner class

The member inner class, which is a member of an external class, can directly use all members and methods of the outer class, even if it is private. While the outer class accesses all member variables/methods of the inner class, it needs to be fetched through the object of the inner class.

2. Local inner class

A local inner class, which refers to an inner class definition within a method and scope. Local inner classes are compiled just like other classes, but only in different scopes, only within the scope of the method or condition, and cannot be referenced after exiting these scopes.

3. Nesting inner classes

Nested inner classes are the inner class that is decorated as static. An inner class declared as static does not require a connection between an inner class object and an external class object, which means that we can refer directly to Outer.Inner, which means that you do not need to create an external class or create an inner class.

There is another difference between nested classes and ordinary inner classes: ordinary inner classes cannot have static data and static properties, and cannot contain nested classes, but nested classes can. Nested classes cannot be declared private, and are generally declared public for easy invocation.

4. Anonymous inner class

An anonymous inner class is an inner class without a name, and because there is no name, an anonymous inner class can only be used once, and it is often used to simplify code writing, but there are prerequisites for using anonymous inner classes: You must inherit from a parent class or implement an interface

Java Internal 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.