Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about inheritance

 
vivien siu
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello guys,
what is the advantage of inheriting a parent class A compared to creating a new object of class A if we want to use class A's method? Is it because of method overriding?
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can achieve code reuse in two ways:

1. implementation-inheritance (Gives you polymorphism as well)
2. composition (Can get polymorphism by using interface-inheritance)

Inheritance allows you to have a default behaviour in your parent class and subclasses can override this default behaviour. Implementation-Inheritance strongly couple classes together. So should favour interface inheritance with composition for reuse over implementation inheritance.

For more details refer Q8-Q10 on free sample PDF download at http://www.lulu.com/content/192463
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic