Geeks Talk

Prepare for your Next Interview




inheritance

This is a discussion on inheritance within the C# forums, part of the Software Development category; explain about inheritance...


Go Back   Geeks Talk > Software Development > C#

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 04-16-2007
Junior Member
 
Join Date: Apr 2007
Location: hyderabad
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
sumad is on a distinguished road
inheritance

explain about inheritance
Reply With Quote
The Following User Says Thank You to sumad For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 04-25-2007
Junior Member
 
Join Date: Apr 2007
Location: Hyderabad
Posts: 16
Thanks: 2
Thanked 1 Time in 1 Post
saswata.purkayastha is on a distinguished road
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.
Reply With Quote
  #3 (permalink)  
Old 04-25-2007
Expert Member
 
Join Date: Nov 2006
Location: Hyd-IND
Posts: 523
Thanks: 1
Thanked 55 Times in 46 Posts
sutnarcha is on a distinguished road
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-
Reply With Quote
  #4 (permalink)  
Old 04-25-2007
Contributing Member
 
Join Date: Mar 2007
Posts: 43
Thanks: 1
Thanked 2 Times in 2 Posts
varmakub is on a distinguished road
Re: inheritance

Here is good link, which answers your question with gud ex :-)
http://www.csharp-station.com/Tutorials/Lesson08.aspx
Reply With Quote
  #5 (permalink)  
Old 06-06-2007
Junior Member
 
Join Date: Feb 2007
Location: Bangalore
Posts: 17
Thanks: 0
Thanked 1 Time in 1 Post
jbanx is on a distinguished road
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
Reply With Quote
Reply

  Geeks Talk > Software Development > C#


Thread Tools
Display Modes


Similar Threads

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


All times are GMT -4. The time now is 12:35 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved