 Hello everyone, I am Mrs. Meenakshi Shreya Gandhi from Walshian Institute of Technology, Sholapur. Welcome to the video lecture on Single Inheritance. Learning outcome? At the end of this session, students will be able to explain and write programs using single inheritance. Let us see what is inheritance is. Here a set of definitions are given which explain what is meant by inheritance. It is the capability of one class to inherit the properties from another class. The technique of building new classes from the existing classes is called as inheritance. The mechanism of deriving a new class from the old one is also called as inheritance. The old class is referred as the base class and the new class is called as the derived class. So, here it shows a structure of inheritance where this class is a base class from which the properties are inherited into the derived class. Let us see what is meant by base class and derived class. The base class is a class whose properties are inherited by another class. A base class is also called as superclass and a derived class is a class which inherits the properties from the base class. The derived class is also called as a subclass. So, here it shows an example where this is a class that is called as a base class or a superclass. The properties of the base class are inherited into the derived class which is also called as a subclass. A derived class can inherit some or all the features of the base class and can add additional features to the derived class. Let us see the types of inheritance. The first is the single inheritance. In this type of inheritance, a derived class is there with only one base class. So, here it shows a structure where we have only one base class from which we are deriving only a single derived class. This is called as a single inheritance. The next is the multiple inheritance. In multiple inheritance, a derived class has several base classes and only one derived class. So, the structure of the multiple inheritance is shown here where it contains more than one base class. From more than one base class, a derived class has been derived. So, in this example, there are two base classes class A and class B. From these two classes, class C has been derived. The next is the hierarchical inheritance. In this, the traits of one base class are inherited by more than one derived class. So, here there is a single base class from which more than one derived class has been derived. This is nothing but hierarchical inheritance. The next is the multilevel inheritance. The mechanism of deriving a new class from another derived class is called as multilevel inheritance. So here, it shows a multilevel inheritance where we have a class A which is a superclass from which the class B has been derived. From this class B, we are deriving one more class that is called as class C. So, class A becomes the superclass that is a base class. Class B becomes the intermediate base class and class C is called as the derived class. The next type of inheritance is called as a hybrid inheritance. So, hybrid inheritance is a combination of more than one type of inheritance. A structure is shown here, it gives an example of hybrid inheritance where it is taking the combination of hierarchical and multiple inheritance. So, in this type of inheritance, hybrid inheritance, it is a combination of multiple and hierarchical, but this combination is always not fixed. We can have a different combination as well. Let us see the next type of access specifier that is called as protected access specifier. So we already know that a private member of a base class cannot be inherited and so not available directly to the derived class. So here it shows a class number where some private members are used and it is visible only to the member function with the same class. So if the private data is made as public, this would make it accessible to all other functions of the program, thus taking away the advantage of data hiding because it is visible to the functions in the program. So all the public data is available to all the functions in the program. This will lose the advantage of data hiding. We have a third visibility label called as protected. So which serves a limited purpose in inheritance. So in this example, it shows a protected member so it serves a limited purpose in inheritance. A member which is declared as protected is accessible by the member function within its class and any class immediately derived from it. So it cannot be accessed by the functions outside these two classes. So a protected member is inherited that is it is visible to the member function of the of its own class and that of the derived class means it is only available within the base class and only in the derived class otherwise it is not accessible outside these two classes. Let us see how to define a derived class. So we can define a derived class by specifying its relationship with the base class in addition to its own details. This can be explained by using the syntax. So here we have a class then followed by the is the derived class name then called in then we have to mention the visibility mode. This visibility mode will tell the mode of derivation of the derived class then that is followed by the base class name. Let us see the modes of derivation. There are in total three modes of derivation that is private derivation, public derivation and protected derivation. Private derivation all the public members of the base class become private members of the derived class and protected members of the base class become private members of the derived class and private members of the base class are not inherited. So this shows the declaration of the base class and this is how the derived class has been defined. here we have the class then followed by the derived class name then we have the mode of derivation here it is private we have to mention it as private then comes the name of the base class so this is how the private derivation is mentioned for the derived class now given the private derivation can be mentioned in this way this is also called as private derivation if I'm not mentioning any mode of derivation over here by default it will take it as the private derivation let us see the public derivation in public derivation all the public members of the base class become public members of the derived class protected members of the base class become protected members of the derived class private members of the base class are not inherited so here it shows how the base class has been defined and this is a derived class which has been derived from the BaseClass and here is the mode of derivation which is declared as PublicDarivation. Let us see the last type of derivation that is called as ProtectorDarivation. In UnderProtectorDarivation, the public members of the BaseClass become Protector members of the derived class. Protector members of the BaseClass become Protector members of the derived class. And private members of the BaseClass are not inherited. So, here it shows the base class has been defined here and this shows how the derived class has been derived with a protected mode of derivation. So this table gives how the base class members under different mode of derivation these are inherited in the derived class. Trying to think and answer what are the advantages and disadvantages of inheritance? Pause the video for some time and note down the answer in your book. Disadvantages and Disadvantages of Inheritance Advantages of inheritance? Inheritance promotes core reusability when a class inherits or derives another class it can access all the functionality of the inherited class. Because of this the size of the code is minimized. The disadvantages of inheritance? Generated functions work slower than the normal function as there is indirection and also often the data members in the base class are left unused which may lead to memory wastage. In this video we are going to focus only on single inheritance. So let us discuss single inheritance. So as we have already discussed a single inheritance is nothing but a derived class with only one base class is called as a single inheritance. That means there is only one base class that is a super class and one derived class that is called as a subclass. So here it shows the structure of a single inheritance where we contain only one base class from which we have derived a single derived class. Let us take an example using single inheritance. So here we have a class called as parent and under public visibility label we have data member integer data member that is idp and we have a member function called as get idp where it is taking one parameter that is x and that value of x is assigned to idp. idp indicates that is the id of the parent. So this is a base class which has been defined here. Then from this class the class child has been declared here with public mode of derivation and it has been derived from the class called as parent. So here the derived class has been defined with public mode of derivation and under public mode of derivation all the public members of the base class become public members of the derived class. Under public visibility label it contains a data member called as idc and a member function called as get idc where it assigns the value of x to the idc data member of class child. And we have one more member function with name display where it displays the id of the parent that is the derived class is accessing the members of the base class and it is displaying the id of the child also. And in the main function first we are declaring the object for the child by using object and dot operator we are calling the get idp member function where 12 will be assigned to the data member idp. And by using the object again we are calling the get idc member function where 24 is assigned to the data member idc. Then after that we are calling the display function where it displays the value of the id of the parent and id of the child. Let us take one more example using single inheritance. We have a class called as student and under protected visibility label there are two data member subject 1 and subject 2 and under public visibility label there is a member function called as get marks where the role of the get marks is to assign the value of x and y to subject 1 and subject 2. So here the base class has been defined. Now there is one more class called as result which has been derived from the class student under protected mode of derivation. So here the derived class has been defined with protected mode of derivation and under protected mode of derivation all the public and protected members of the base class become protected members of the derived class. Under public there is a data member total and there is a member function called as display. And the display here is calling the member function get marks which is actually has been inherited in the derived class under protected. As it has been derived under protected we already know that the protected members are never accessible from the main function. That is why the get marks member function has been called from the class result. So when we call the get marks member function it will assign 74 to subject 1 and 84 to subject 2. So here it is the derived class is accessing the member function of the base class. After that the total of the subject 1 and subject 2 is done and it is displaying the total marks of the two subjects. In the main function first we are creating the object for the class result and by using the object and the dot operator we are calling the member function display where it will call the get marks function first, where it will assign 74 to subject 1 and 84 to subject 2 and the total of these two subjects is calculated and the total marks are discrete. These are my references, thank you.