2.24 Java Basics Summary ① inner class basics

Source: Internet
Author: User

Inner class Basics
Classes are defined inside the class, either in the member's inner class or in the local inner class (inside the method)

First, members of the internal class
① can have access modifiers
②class File Name: External class class name $ internal class class name. class
③ is a complete, independent class
④ can be new in any of these non-static places, but external class objects must be used in third parties. New way of generating inner class
Student s = outside.new Student ();
⑤ static inner class--special case
In any method of this class can be new out, in the third party Chinese medicine new out, no need to produce external class object, only need to use the external class name. The method

Second, local internal class
① cannot have access modifiers
②class file name: External List $ ordinal inner class. class
③ is a complete, independent class
④ produces objects in this class of methods, using the
⑤ anonymous inner class--special case
Because there is no class name, the object is generated by using a statement to tell the JVM of his structure;
And can only be used once

New Object () {
void Hello () {}
}.hello ();
This is a statement, an anonymous object. Method Name

All the parent classes can write like this.

Human hu = new Human () {
public void Dance () {//Override
}
};//here is a semicolon, equivalent to a statement
HU.DANGCE ();
File name: Inner class $ ordinal. Class


☆ Three types of file names
Out$in.class
Out$1in.class
Out$1.class

2.24 Java Basics Summary ① inner class basics

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.