-1

We know a Class is usually been loaded into meta space, but what about an nonstatic inner class? where it goes when it has been loaded?

class OuterClass {
    /**
     * Where is this class? would this class goes to the meta space?
     */
    class InnerClass{
        public void method(){
            /**
             * And where is this class?
             */
            class InnerClassInMethod{
                public void method(){
                    System.out.println("Hello");
                }
            }

            new LocalClass().method();
        }
    }
}

And when the class would be loaded? it would be loaded as well as the outer class or deferred until an instance has been requested? And, same question for they are going to be unloaded?

user3593261
  • 560
  • 4
  • 17

1 Answers1

1

In the MetaSpace as well. The only one difference between static and non-static classes is non-static class contains reference this to the parent class.

Andy Turner
  • 137,514
  • 11
  • 162
  • 243
Oleg Cherednik
  • 17,377
  • 4
  • 21
  • 35