0

How are we able to access static member of normal Inner class without creating an Outer class object in JAVA?

Because Inner class is like an instance member of Outer class, an Outer class Object is required to access its instance members.

I mean how are we able to access directly inner class: Inner.m1() without Outer class Object? (Not talking about accessing m1() directly using inner class name as it is static)

class Outer
{
    class Inner
    {
       static void m1()
       {
           
       }
    }
    public static void main (String[] args)
    {
        Inner.m1(); // NO C.E !
    }
} 

Best regards.

JhonM
  • 1
  • 1
  • maybe this line of [JLS 8.1.3. Inner Classes and Enclosing Instances](https://docs.oracle.com/javase/specs/jls/se19/html/jls-8.html#jls-8.1.3-130) can help: "*All of the rules that apply to nested classes apply to inner classes. In particular, an inner class may declare and inherit static members ([§8.2](https://docs.oracle.com/javase/specs/jls/se19/html/jls-8.html#jls-8.2)), and declare static initializers ([§8.7](https://docs.oracle.com/javase/specs/jls/se19/html/jls-8.html#jls-8.7)), even though the inner class itself is not static.*" – user16320675 Mar 04 '23 at 12:25

0 Answers0