views:

64

answers:

4

hi all, i m in a confusion that while extending any class, which class (child or parent) size get larger logically. thanks in advance

+1  A: 

The parent class itself stays the same size.

The size of an instance of the child class is greater than or equal to the size of an instance of the parent class.

Jon Skeet
A: 

I think you mean the object (the instance of that class) an object that extends a class will have memory allocated for the subclass like normal, as well as any methods/variables used in the superclass.

as a rule of thumb, you can just think of a subclass object containing all of the memory from it and all superclasses.

Robert Greiner
A: 

The child would have a larger memory footprint. The parent doesn't know about the child.

Joseph
A: 

The parent class pretty well has to stay the same size. Otherwise, you'd change the results of a routine using the parent class just by defining a child class, and that would be bad. For one thing, it would violate the Principle of Least Astonishment, and also it would introduce very undesirable coupling.

The child class has to have everything from the parent class and presumably some extras (or it wouldn't be a child). However, while it will normally be larger than the parent, it doesn't actually get larger. Its size is normally determined when it is defined. (At least for all languages I'm familiar with. If this question is truly language-agnostic, well, there's lots of object-oriented systems out there.)

David Thornley
hi david,thnx for replying, then why cant we make object of super class object as child contains all of the code in it but the reverse way round is possible.