Inheritance – An Overview
The function of inheritance is importance in C++. It helps us in making the ladder of different classes. In such programs, theoretical ideas provide the structure of a program. Like the class animal has cat and lion as it’s innate. Both of them have some qualities similar to other animals and some qualities specific for them selves.
Programmers can enjoy many opportunities by inheritance. Here, we are going to explain the main format of the inheritance.
In inheritance, it is possible that a class can succeed to a rather different class. But it is good to use inheritance when we have a class which shows a set of items. Every part related to the set will be shown in the universal class. It is known as the base class. So, in base class the functions are inherited to other classes. Such classes are recognized as derived classes. It is must that the variables present in the derived classes must be present in the base class.
Here, we are going to make a program which will show the connection between different kinds of organism. There will be any base classes which will have derives classes as well. If you like to make a lot of classes then divide the base class into land animals, trees animals, water animals and flying animals etc. even we can make more special classes like the classes of lions and bears, flowers and grass etc.
There is a system of division of data in the classes. The variables and functions related to base class are mostly shared by the derived classes. The base class has different ways of sharing the information. The variables and functions which are made for public use can be shared by derived classes as well as the classes which are not related to base class. The derived classes get opportunity of access to the base class data. But this access has three different levels according to its security purposes. These are public, private and protected. In public information, all the functions as well as variables are in the approach of derived and other classes. But the private variables can neither be checked by derived nor other classes. In protected, all the variables and functions can not be checked by any outside class. They are only in access of derived classes. Protected information is good way and better to use when there are large number of items.