Question 1 - Can a non-static inner class be loaded without any explicit object of the Outer class?
Yes, you can load a non-static inner class this way, see the example below:
class MyObject { class InnerObject { static final String prop = "SOME INNER VALUE"; } static void doLoad() { System.out.println(InnerObject.prop); } }
The fact is that there are not many reasons for this, because a non-stationary inner class cannot have any static blocks, methods, fields, if they are not final, as in the question below.
Question 2 . Why do we have compile-time constants (String literals, since they are handled in a special way in the String pool and primitive types), can be made static in a non-stationary inner class?
Java designed in such a way that you can use static , final fields in non-static inner classes.
source share