When you create object B, say by calling the default constructor
B myObject = new B();
The JVM then allocates the object more or less:
- There is enough memory for each field explicitly declared in B (usually about 4-8 bytes per field, but it varies greatly between types and host system).
- Enough memory for every possible field inherited by A and his ancestors
- Enough memory to contain a link to the send vector (which should also be about 4-8 bytes)
The send vector is used by the compiler to store the address of each method that can be called for a given object, and depends on the class of the object, and not on the instance of the object itself (each object B has the same interface in the end!)
Therefore, you do not need to select A because there is no separate object A. You do not create 2 separate objects. When you create B, you create a βspecializedβ version of A .. that can be thought of as A with something more. Therefore, you need to select only B (but keep in mind that B also has everything that its ancestors have)
Alex 06 Oct 2018-11-11T00: 00Z
source share