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

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
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: 8626

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.


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Ishan Pandya
Ranch Hand

Joined: Feb 06, 2012
Posts: 224

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.

It is sorta covered in the JavaRanch Style Guide.
subject: Inheritance