Saturday, 24 August 2013

What is Inheritance

Inheritance is the major and usable principal of OOP.
here just we see and understand the concept of inheritance ..Further clarification in practical programming.So lets try to understand it.

As the name inheritance suggests an object is able to inherit characteristics from another object.
By example we can see the real world example like
Let's say we make a class called "Human" that represents our physical characteristics. It's a generic class that could represent you, me or anyone in the world. Its state keeps track of things like number of legs, number of arms, and blood type. It has behaviors like eat, sleep, and walk. Human is good for getting an overall sense of what makes us all the same but it can't for instance tell me about gender differences. For that we'd need to make two new class types called "Man" and "Woman". The state and behaviors of these two classes will differ from each other in a lot of ways except for the ones that their inherit from Human.
Inheritance enables you to create new classes that reuse, extend, and modify the behavior that is defined in other classes. The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class. A derived class can have only one direct base class.

Here is the method and variable of class in diagram ,like animal can "EAT" this is the method or action that they can perform of any type mammal.

No comments:

Post a Comment