Jesper Young wrote:Inheritance is one of the fundamental features of object-oriented programming. It's main uses are to enable polymorphism and to be able to reuse code for different classes by putting it in a common superclass (although it's not a good idea to create a superclass just for the sake of sharing code - class designs should not break the Liskov substitution principle).
Prakash Attur wrote:if you have a class Car with some general methods and fields that all cars have... for example brake,sterring,wheel,etc..
now if you do code for AmbassadorCar, you need not to do the same thing which is already done in Car class, you can make use of that..(re-inventing the same thing is foolish)...
now if do code for BenzCar, you will have some extra feature of everything what normal has...i.e you will have steering here also but that may power steering,then hand brake etc..also you can add some more things here like AC,MP3 player etc...
Finally what i am trying to tell you is Super class will be more general.. in the sub class you can give specific implementation to the super class methods...
Arun Singh Raaj wrote:Abstraction, Encapsulation are important for a large application or just an application. Hence to achieve these features, inheritance is necessary.
Consider Paul's rocket mass heater. |