explain about inheritance
explain about inheritance
Inheritance lets you reuse the state and behaviour of a object to create a new object;Inherit from a class whose state and behaviour u need to extend and thats it.
Advantages:
->Code Reuse.
->Implement Polymorphic behaviour.
Inheritance is reusing the properties and methods of a parent class into a sub class.
Eg.
Following are the 2 classes that are designed without following the inheritance concepts.
Class: means-of-transport
Properties: wheels, seats, body-type, runs-on
Methods: start, run, stop
Class: car
Properties: name, wheels, seats, body-type, runs-on, manufacturer, fuel-type
Methods: start, run-forward, run-backward, stop
As we see there is duplication of data. To avoid duplication, the class ‘car’ can be declared as sub class of the class ‘means-of-transport’ inheriting some of its properties as shown below.
Class: means-of-transport
Properties: wheels, seats, body-type, runs-on
Methods: start, run, stop
Class: car INHERITS means-of transport
Properties: name, manufacturer, fuel-type
Methods: run-forward, run-backward
Assumptions: some means of transport may not run backwards, but car can. Every means of transport will have some number of wheels, some number of seats, some body type and runs on something or the other including a car. Every means of transport starts and stops.
Lack of WILL POWER has caused more failure than
lack of INTELLIGENCE or ABILITY.
-sutnarcha-
Here is good link, which answers your question with gud ex :-)
http://www.csharp-station.com/Tutorials/Lesson08.aspx
Inheritance is a way of reusing the method, properties etc. This allows you to define class for very specific reason and inherit rest of the methods and properties from base class (which again is specifi for its own reason). This also gives you Hierarchical approach to you project