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