What is an inner class
A class inside a class is called an inner class.
Inner classes can be well hidden. Generally, non-inner classes are not allowed to have private and protected permissions, but inner classes can. The inner class has access to all elements of the outer class.
Internal class classification:
Internal classes can be divided into: instance internal classes, static internal classes and member internal classes. Each internal class has its specific Features.
If class B is defined in class A, then class B is an inner class, also called a nested class. Relatively speaking, class A is an outer class. If there are multiple levels of nesting, such as class A with inner class B, and class B with inner class C, then the outermost class is usually called the top-level class (or top-level class).
Internal classes can also be divided into various forms, which are very similar to variables, as shown in Figure 1:
Features of internal classes:
1. The internal class is still an independent class. After compilation, the internal 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, you cannot access the member variables of the outer class casually. You can still only access the static member variables of the outer class.
Recommended tutorial: Java tutorial
The above is the detailed content of What are inner classes in java. For more information, please follow other related articles on the PHP Chinese website!