Java programming notes 8 object-oriented three internal classes

Source: Internet
Author: User

A) Anonymous class (different from anonymous objects)

There is no clear class definition format, which refers to the combination of class definition and Class Object creation.

An anonymous class is a unique object and defines an anonymous class when an interface is generated.

 

B) Static class

Static classes exist in a class as static members of the class,

Class outerclass

{

Static class innerclass

{

.....

}

}

It can be viewed as a static member of the class. Static members can directly use it without creating an outerclass object, that is, they can directly create an innerclass object without creating an outerclass object.

Inside outerclass:

Innerclass OBJ = new innerclass ();

Outside outerclass:

Outerclass. innerclass OBJ = new outerclass. innerclass ();

 

C) member class

 

A member class is a common member variable in a class. Defining a member class is no different from defining a general class.

Class outerclass

{

Class innerclass

{

.....

}

}

 

Like using common member variables, an innerclass object can be created only after an outerclass object is created.

Outerclass objout = new outerclass ();

Objout. innerclass objin = new objout. innerclass ();

 

D) Local class

The local class is defined inside the method like the local variable. The local class can only be used inside the method, and disappears after the method is executed.

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.