File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance" Watch "Inheritance" New topic


Aashutosh Yadav

Joined: Mar 01, 2013
Posts: 1

if we inherit a class then does it increase the size of the child's object in memory ?
e.g. let a class has two instance variable and two methods,on creating its object it cover some space in memory.
Now if this class inherits a class having two public variables and tow public methods, now does this increase the space covered by child class's object in memory ?
please explain it in context of normal class,abstract class and interface............!!!
Winston Gutkowski

Joined: Mar 17, 2011
Posts: 8927

Aashutosh Yadav wrote:if we inherit a class then does it increase the size of the child's object in memory ?

Simple answer: probably.

Proper answer: Without a lot of testing you simply don't know, because AFAIK it is not specified in the JVM spec.

It's also something you really don't need to concern yourself with. Java memory is the business of the JVM, not you.


Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here
Ishan Pandya
Ranch Hand

Joined: Feb 06, 2012
Posts: 225

As far as i think some pointers from the subclass to the instances of superclass are created.
Actually i dont think it is specified anywhere as Mr.Winston said.

I agree. Here's the link:
subject: Inheritance
It's not a secret anymore!