Java Nested classes

Source: Internet
Author: User

First, nested class

Using nested classes reduces naming conflicts , and an inner class can be defined in a class , in a method , or even in an expression .

(1) Definition: A nested (nested) class is any class whose declaration occurs within the body of another class or interface.

(2) Nested classes are divided into two types: static nested classes and non-static nested classes, and non-static nested classes are inner classes (inner Class).

The inner class is divided into four types:
Static Nested Classes (Static nested classes)
member Inner class (Member inner classes)
local inner class (Local inner classes)
Anonymous Inner class (Anonymous inner classes)

Second, Static nesting class

A static class, the simplest nested class, can only access static member variables and static methods of external classes .

1. Static classes cannot access non-static members of external classes and non-static methods (whether public or private);
2, the static class instance does not need to instantiate the Barbarian member first, can instantiate directly.

 Public class outer{    publicstaticclass  nestedclass{   }}

Java Nested classes

Related Article

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.