Summary of internal class usage in Java

Source: Internet
Author: User

1) The advantage of an inner class is that the inner class can access the private member variable of the outer class without needing the object of the new outer class.

2) The inner class is divided into: Static inner class, anonymous inner class, local inner class, member inner class.

3) The scenario for static inner classes is that only static member variables and static member methods of external classes can be accessed.

4) The application scenario for a member's inner class is that it can access all the member variables and methods of its outer class, whether static or non-static.

5) Local inner classes: Like local variables, cannot be modified by public, protected, private, and static. Only local variables of the final type defined in the method can be accessed.

6) Anonymous inner class: Anonymous inner class is a local inner class without a name, not using the keyword class, extends, implements, no constructor method. An anonymous inner class implicitly inherits a parent class or implements an interface. Anonymous inner classes are used more often as a method parameter.

Summary of internal class usage in 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.