1, the inner class can be regarded as the field of the outer class, the modifiers and meanings used are the same as field (field uses the same modifier and method), you can also use Final,static,abstract
2. Generate inner classes in the outer class
Class outer{
Class inner{
}
}
Class test{
public void Main (string[] args) {
Outer o=new Outer ();
Outer.Inner i=o.new Inner ();
}
}
3. Method of accessing the field of an external class in an inner class: OuterClassName.this.FieldName
4. Internal classes defined in the method to access local variables in the method, these variables must be declared as final
5. Non-static inner class cannot declare static method
6, the inheritance of the inner class:
Class car{
Class wheel{
}
}
Class Planewheel extends car.wheel{
This constructor is required to establish a reference relationship between the inner class and the outer class
Planewheel (car car) {
Car.super ();
}
public static void Main (string[] args) {
Car car=new car ();
Planewheel pw=new Planewheel (CAR);
}
}
7, using anonymous internal classes to implement the interface
Interface animal{
void Eat ();
void run ();
}
public class zoo{
Public Animal Getanimal () {
return new Animal () {
public void Eat () {
}
public void Run () {
}
};// “;” Not less
}
}
Java Internal classes