Prepare for your Next Interview
This is a discussion on inheritance within the C# forums, part of the Software Development category; explain about inheritance...
|
|||
|
inheritance
explain about inheritance
|
| The Following User Says Thank You to sumad For This Useful Post: | ||
| Sponsored Links |
|
|||
|
Re: 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. |
|
|||
|
Re: inheritance
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- |
|
|||
|
Re: inheritance
Here is good link, which answers your question with gud ex :-)
http://www.csharp-station.com/Tutorials/Lesson08.aspx |
|
|||
|
Re: inheritance
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
|
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Types of Inheritance | scott | OOPS | 15 | 10-22-2008 05:05 AM |
| multiple inheritance in java... | psuresh1982 | Java | 20 | 07-23-2007 02:33 PM |
| multiple inheritance.... | psuresh1982 | Java | 2 | 01-22-2007 12:57 AM |