Java Public lesson -03-inner class

Source: Internet
Author: User

Inner class

(). The role of the inner class.

1. Implements the hiding of the inner class.

2. Multiple inheritance was achieved.

3. The inner class has access to properties and methods owned by all external classes.

4. Avoid modifying the interface when the same name method appears.

I. member INNER class.

1. If we want to access the inner class, we must have an instance of the outer class! Access can only be accessed through an external class.

2. The member inner class can have private,protected access.

Two. local inner class.

1. Must be in a method or scope.

2. Rights are limited to the internal role of the method body.

3. When the formal parameter of our method needs to be used in the inner class! Then this parameter must be final decorated.

Three. Static Inner class:

1. Do not rely on external classes.

2. Add the modifier static to the inner class.

3. Cannot access external class non-static methods and properties.

Four. Anonymous inner class:

1. No name.

2. Requires that all anonymous inner classes must implement an excuse or inherit a class.

3. When the formal parameter of our method needs to be used in the inner class! Then this formal parameter is more than the vegetarian final modification;

Java Public lesson -03-inner class

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.