Results 1 to 5 of 5

Thread: inheritance

  1. #1
    Junior Member
    Join Date
    Apr 2007
    Answers
    1

    inheritance

    explain about inheritance


  2. #2

    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.


  3. #3
    Expert Member
    Join Date
    Nov 2006
    Answers
    518

    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-

  4. #4
    Contributing Member
    Join Date
    Mar 2007
    Answers
    42

    Re: inheritance

    Here is good link, which answers your question with gud ex :-)
    http://www.csharp-station.com/Tutorials/Lesson08.aspx


  5. #5
    Junior Member
    Join Date
    Feb 2007
    Answers
    17

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact