When a class is defined inside another class, the class is called an inner class.
Common characteristics of internal classes (Recommended learning: java course )
(1),The inner class is still an independent class. After compilation, the inner class will be compiled into an independent .class file, but it will be preceded by the class name of the external class and the $ symbol.
(2). Internal classes cannot be accessed in ordinary ways. The inner class is a member of the outer class, so the inner class can freely access the member variables of the outer class, whether private or not.
(3) If the inner class is declared static, it cannot access the member variables of the outer class casually. At this time, the inner class can only access the static member variables of the outer class.
Member inner class
class Outer { class Inner{} }
Compiling the above code will produce two files: Outer.class and Outer$Inner.class.
Method inner class
Put the class inside the method
class Outer { public void doSomething(){ class Inner{ public void seeOuter(){ } } } }
The above is the detailed content of what are java inner classes. For more information, please follow other related articles on the PHP Chinese website!