No double overhead.
Java will take the class, superclasses, calculate the space needed for all fields, and allocate the space needed for one instance.
Create only a memory point, there is no concept of a superclass at all, there is an instance of Foo that needs memory for only one int, and instances of Bar that need memory for two ints, of which one is there, because Bar appears to be expanding Foo.
This way, overhead (or bookkeeping or whatever you want to call) happens only once.
However, when developing in java it is usually better not to care about the memory material too much unless you have very specific (and I mean very very specific) use cases in which the overhead of the book causes serious problems. In this case, an 8-byte addition should also be considered.
There are usually many other ways to improve the memory size of your application or its overall performance, rather than worry about the memory overhead of each individual instance.
Simone gianni
source share