OOPS Inheritance

Inheritance is the capability of one class to acquire properties and characteristics from another class. The class whose properties are inherited by other class is called the Parent or Base or Super class. And, the class which inherits properties of other class is called Child or Derived or Sub class.

Inheritance makes the code reusable. When we inherit an existing class, all its methods and fields become available in the new class, hence code is reused.

NOTE : All members of a class except Private, are inherited.

Purpose of inheritance:-
- Code Re-usability.
- Method overriding.
- Use of virtual keyword. 


class Animal
{ public:
  int legs = 4;
};

class Dog : Animal
{ public:
  int tail = 1;
};

No comments:

Post a Comment