Difference between static inner class and inner class in Java

 

A static inner class can be instantiated without relying on an instance of the outer class, while an inner class requires an instance of the outer class to complete the instantiation;

 

Static inner classes cannot access non-static members of outer classes (you can create objects of outer classes to access), inner classes can access all members of outer classes;

 

Members of static inner classes can be static, but members of inner classes cannot be static;

 

The loading of static members is completed when the class is loaded, and the inner class is compiled after the outer class is compiled, so the static members are loaded before the inner class is loaded at compile time, which is obviously unreasonable.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326227008&siteId=291194637