 Hello, everyone. Welcome to Python tutorials. Myself, Samprit Patel, Assistant Professor, Department of Computer Science and Engineering, Valchand Institute of Technology, Sholapur. We'll continue a previous video about inheritance in Python. So at the end of this video, you'll be able to write a Python script in object-oriented programming style. In the previous video of inheritance, we have seen how to implement single inheritance, multiple inheritance and multi-level inheritance. In this video, we will go through some hands-on session of creating or understanding how to create hierarchical inheritance and hybrid inheritance. So let's go on to the session. So to create or what is hierarchical inheritance, when more than one derived classes are created from a single base class, then this type of inheritance is called hierarchical inheritance. So the example we are going to see is we have a parent as a base class, and this base class will have two child classes that is two derived classes. So let's create a base class, say class parent, and this will have, let's take a simple function, say function one, which will print, which will print this function is of parent class. Now we'll have a derived class, class, say child one, which will inherit parent class, which will inherit parent class. Okay, now this class will have a function, say define a function, function two, and this will print, this will print, this function is of child one class. Okay, so this particular print statement is just for the understanding of how the objects are accessing functions of different classes. So now we'll have a second derived class that is class child two, this will also inherit parent class. So see here, here both child one and child two are inheriting a single parent class. Okay, single parent class. So this will have a function, say function three, which will print, which will print this function is child two class. Okay, now once we have created a hierarchical inheritance by inheriting a single parent class into both the derived classes, we'll have to see how the objects actually work, how the objects actually work. So create two objects OBJ one and OBJ two. So OBJ one will be an object of child one class, whereas OBJ two will be an object of child two class. Now, with the help of first object, that is OBJ one, I'll try to access function one and function two, that is of its own class, okay, function two. Okay, and with the help of OBJ two, I'll again access function one and function three. Okay, so function three is the function of its own class. Okay, so let's run this. Now here you can see that object one can also access parent class and object two can also access parent class as they are inheriting the parent class separately. Okay, so if I try to access function two with the help of the second object, say function two, this will generate an error, it will not have an access to that particular class. Okay, so see attribute error child two instance has no attribute called function name. Okay, so this is an example of hierarchical inheritance. Now moving forward to the last type of inheritance, that is hybrid inheritance. So hybrid inheritance consists of multiple types of inheritance applied in a single program. So this is called as hybrid inheritance. Let's see an example of hybrid inheritance. So here we'll take a class, school, class, school, and we'll have a function, say function one. So this will print function is from class school. Now we'll create a class student, class student one, which will inherit, which will inherit school. And again, we'll have a function. So I'll just define function two. Okay, and this will print, this will print that function is from student one, student one. Now we'll have another class, class student two, student two, which will inherit again, school, which will inherit school. And this will have a function define function three, it will print function is from student two class. Now this, tell me what type of inheritance is this. So this is hierarchical inheritance, it has a single parent class, and it has a two derived classes. Okay, now we'll create now we'll create class student three. Now this class will inherit, will inherit student one and student two. Okay, this class is inheriting student one and student two. And it will have a function, say function four, which will print is from student three. Yes, now C will create an object only of this class. So if you see first three classes, it is my hierarchical inheritance, whereas if you see this three classes, it is multiple inheritance. Okay, is it clear? So we'll create an object of class three, or say student three. So this should be student three. Yes, and with the help of this object, you can access obj.function one. Okay, so let's just run this. Okay, so the brackets are missing. Yes, so let's if I run this C student three is accessing function one. So in spite of having function student one and student two inherited, it can also access school because school is the parent class of student one and student two. So try to answer this question that suppose B is a subclass of A to invoke the constructor method of A from B what the line of code should be written. So is A, B, C or D? What is the possibility or which is the option that is right to access or invoke instructor of method A from B. So yes, A is the correct option. Why to invoke the constructor of method A from B, either the following should be written that is a dot constructor that is calling itself constructor or to use a super method from the second class that is the derived class. Okay, so now many a times it is required that you don't need some members to be accessed by the class. Okay, so to have that we can restrict the access of the variables by the derived class or child class. So we can make some of the instance variables of the parent class as private. Okay, so let's see an example quick example. So class C class C. Okay, so it will have self dot C is equals to 21. And we have self dot underscore underscore C D. So if you want to make a variable private you have to use double underscore that is 42 will just give some values. Now we'll have class D which inherits C and we'll try to define a constructor. Okay, define a constructor which will have self dot E is equals to say 84. And C dot will call the constructor in it will have self. So yes, this particular value is to be given in a constructor. Okay. So now if I try to print, if I try to print the value of D using the object of class D. So obj is equals to D and using this print obj dot D which is an attribute of C class which is private, it will return you an error that D instance is not an attribute of D. Okay, so this is how we can create private variables. These are some references I've used to create this video. Thank you.