What is Inheritance? - C++

What is Inheritance? Explain it with an example.

Inheritance :
- One of the most important features of OO design is code-reusability and it is achieved through inheritance. Inheritance is the process by which objects of one class acquire the properties of another class. By this we can add additional features to an existing class without modifying it. This is possible by deriving a new class from the existing one. The new class will have combined features of both the classes.
- This allows the programmer to reuse a class that is almost, but not exactly, what he wants and change it according to his needs.
Class Bird
{
   bool has_feathers;
   int legs;
   public:
   {
       //Functions to manipulate data
   }
};

Class FlyingBird : public Bird
{
   int highestAltitude;
   public:
   {
       //Functions to manipulate data
   }
};
- Here, Class FlyingBird is derived from Class Bird. FlyingBird has all the attributes of Bird plus it has its own attribute highestAltitude which tells the highest altitude at which it can fly. Bird is called as base class and FlyingBird is called as derived class.
Define object, classes and instances.
Define object, classes and instances - Object is the basic run time entity in an Object Oriented (OO) System...
What is multiple inheritance? - C++
What is multiple inheritance? - When a class is derived from another class ie it inherits functionalities of another class, this phenomenon is known as inheritance....
What are the syntax and semantics for a function template? - C++
Function template - Templates is one of the features of C++. Using templates, C++ provides a support for generic programming....
Post your comment
Discussion Board
inheritance
thanks buddy i got d clear idea with ur example
suraj panjwani 03-2-2012