• Post Reply Bookmark Topic Watch Topic
  • New Topic

Someone explain me on inhertance.  RSS feed

 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In inheritance if the subclass inherits all(not final) the methods of the super class,but the methods of super class are stored in sub class object or in superclass object or in both,if both there should be unnecessary memory allocation.please explain me how inheritance works.
 
Mark Newton
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really understand your question, but I think that this other topic is talking about something similar.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I THINK you're asking if it's a waste of space in memory when a sub class inherits the super class methods.

The code for the method is only stored in one place - and the same code is used whether it's called on a super or sub class. There is no duplication for each sub-class.
 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear,Fred YOUR THINK is correct ,but i couldn't get that "The code for the method is only stored in one place".
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but the methods of super class are stored in sub class object or in superclass object or in both,if both there should be unnecessary memory allocation.

You can test this by creating a large class A with many methods, and a class B that extends it, but defines no methods of its own. Observe the file size of both class files. What do you infer from that?

Then you'll understand what Fred was talking about.
[ February 10, 2008: Message edited by: Ulf Dittmer ]
 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf Dittmer for yor suggestion .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!