For making your mind familiar to the concept of inheritance, it is good for you to study the chapter nineteen. In this lesson, you will get introduction of these syntax related to inheritance and the way of using public, protected and private. The format to indicate a class is class Lion: public Animal. So, the real syntax is “public base_class_name”. Here, the class has all the public as well as protected parts of base class. Each and every class has different type of data due to the limitations of access to classes. If there are two objects which have the same name, may not have the same data in them. It is due to the difference of restriction of contact with functions and variables.
The format is given below in the form of an example:
//Functions as well as information is included in the animal class
//associated to each and every animal
class Cat : public Animal
//For those of you familiar with cats
//All the operations have no similarity
//for your close friends as well as foes
Public, protected, and private variables are helpful when we talk about inheritance. These are useful for the management of accessing procedure to the data saved in the class.
It is simple and accessible level. The data which is saved in the public is allowed to be checked by the derived classes as well as the classes which are not included in the list. Even the functions which are known as public share the data with unknown classes. The class which is left should not be seen by the user. Everything which is present in public is open until the start of next class. The format of public is given here.
The data which is described as private is also gathered by the derived classes. If there are two objects having one type then it is not possible that they will have the same data. The format of private is just like the public,
The most secure level of concealing the data is the private. The data which has got the label of private can not be seen by any class whether it is included in the list or not. The functions of private can not get inherited. The format is given below: