In your example
class MyClass { private class InnerClass { } }
creating an MyClass object does not automatically create an InnerClass object, so the object cannot be "always inside an external object." Moreover, you can create any number of InnerClass objects for each MyClass object, so there can not be enough space for the MyClass object for all these objects.
// numbers: MyClass InnerClass MyClass m = new MyClass(); // 1 0 MyClass.InnerClass i = m.new InnerClass(); // 1 1 MyClass.InnerClass[] array = new MyClass.InnerClass[20]; // 1 1 for(int i = 0; i < 20; i++) { array[i] = m.new InnerClass(); } // 1 21
The MyClass object can be used wherever any other object can be used, so they need all the normal information necessary for normal objects.
Thus, InnerClass objects have the same overhead as objects of ordinary classes and even additionally one link (for non-static inner classes), since each internal object must know its own external object.
source share