INHERITANCE(HIERARCHICAL,MULTIPLE) - PYTHON PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in the previous session we have seen the implementation of single inheritance and multi-level inheritance and in today's session we'll go with the two more inheritance concept that is hierarchical inheritance as well as the multiple inheritance right so this we call the working of inheritance concept so inheritance means acquiring the properties of one task with the another so the task here we deal with the two classes that is a base class and derived class so then I will class we inherit the properties from the base class so base class can be called as a parent class and then our class can be called as a check in class so then we have seen in the previous session now directly go with the hierarchical inheritance right so Hainan tell inheritance so hierarchical inheritance means one base class will be there and from that base class we can derive a multiple number of taxes so one parent and multiple chains is called a hierarchical inheritance see this class and it can help Darrell plus one the develop class - so one base class and multiple different answers so two gases will be inheriting the properties from the same base class this we call it as a siblings okay so this is called a parent class feeling so this we can call it as a chain one and this we can call it as a change - so two children for a spade right so this children will access the method something big see here chain 1 and J 2 both are independent classes now I will write the condition the class parent : so we write the function so DF p display and ID on the one parameter cell and then I'll write the print statement simply so parent right now the right of one whole class pass chain one which is inherited from the parent for how to write the base class name as a parameter for this chain one so BEF CC one display self and print chain one and similarly class change boom and again this is in helping the properties of a parent itself right so I break the function being fc2 display and give the parameter self and bring Shae right so hope you understood this one so two children for the same pain right so change like acquiring the properties of painting change is also putting the properties of same period now in order to access the method of feeding is if we can create an object for chain one or you can create an object for chain so if you are creating the object for chain 1 C 1 is equal to chain 1 and through the C 1 we can access the methods of chain 1 and pin but not change too because change it to is completely different change the two is not inhibited from chain 1 change the 2 is inherited from pain so C 1 dot p display C well dot C 1 this way so change one object can be accessing the properties of MN properties give me two variables and methods of change one and the pain but not to change it and if you want to access the chain 2 so we have to create a virtual object for chain to chain will do so through this object also we can access the pattern because in so C 2 dot p display C 2 dot C to disagree okay hope you understood this one so chain 2 is inheriting the properties of parent so if you are creating an object for change to that cannot be accessed the methods of change one right so from the object of China to we can access the methods of change to a period because parent is a base class in change to use it they remember us similarly change one ops so here the second object is accessing the methods of parent and change one change to object is created and tend to object leaves accessing the method soft change it to end parent so this is how we can implement this high level inheritance so this is hierarchical inheritance right so hope you understood this one next the multiple inheritance so I will show all these things by implementing the programs for everything so I will implement the hierarchical inheritance and a multiple narratives let us complete the theoretical concept and then we will see them factor for multiple inheritance so again multiple inheritance means so if there are class is acquiring the properties from multiple parents so here CBS ps1 this class - and this is requiring the properties of four different games so this dinner gas is recording the properties of two breast cancers so from two basic answers we are getting the better breasts so through this object we can access the methods of this guy's one invest less so simply we can say this else it's a father class it's a model class and so change is acquiring the properties of both father and mother so this is the best example so they write the program so let us find the class father so be if you display self right father similarly class mother so this is also an independent gas because both are the base classes so this is not an image etiquette class young display self mother and now we are creating that there are crafted so Jane is Adam class it is the removed from both father and mother so here we have to pass both the base class names and the parameters to the table separated with the car so Jade of further comma so we have to pass the parameters right we have to pass the base name may be base cast me as a parameters operated with a comma if if the devil class is acquiring the properties from multiple based answers so the F C display self great okay now we can create an object for chain which can access the methods of both are all the three that means case methods mother methods and father metals so C 1 is equal to change this so you can access C 1 dot s'il-vous-plait which is a method return in change class similar receiver got yum display which is returning mother class C 1 dot yep display which is written in Pisces so this is how we can implement the multiple inheritance so this multiple inheritance cannot be issued directly in Java programming so in Java this multiple inheritance can be a to do with the interfaces through the interface concept here there is no concept of interface and directly we can pass with base class names separated with a comma as a parameter to the derived class so that it will acquire the properties from all the base classes so by creating an object from the chain we can access the methods of both the base classes so this is for a multiple inheritance so multiple base classes will be there and one day of class requiring the properties from multiple blade base classes C so acquiring the properties means accessing the variables and methods right so hope you understood this one so there are multiple inheritance now we will see the implementation part of this I have connected spent multiple inheritance in system and we have covered the intervene inheritance concept and we have seen the for inheritance types there is a single inheritance multi-level inheritance which we have covered in the previous session and in this session without over the multiple inheritance so hope you understood this concept now let us see the implementation part of these multiple inheritance and hierarchical inheritance in Python interpreter let's move on to the Python interpreter elephants so now we will see the implementation of the hierarchical inheritance and the multi-level inheritance see first we will create a file I'm in class so parent so I am writing some function sorry display self so always we have to pass one parameter into the punch in your function write print peer in class right now I am creating one child child one which in which is inherited from parent and again I am writing here see one display child 1 class again I am writing the child to write again it is also inherited from the same parent so that means this is this is called a hierarchical inheritance so one parent can have a multiple child so multiple classes can acquire the properties from the same period see see to display again I have to pass one parameter print child two papers see here we have written the three classes but the two classes are acquiring the properties from this same parent class so we can call them as siblings l1 and l2 right so child one acquires the properties of parent and similarly child who is also acquiring the properties of the period so we can create the object for child 1 C 1 is equal to child 1 and with that we can access only the methods of children and parent we cannot access the methods of child - because tell you 2 is an another class which i acquire the properties of parent so c 1 dot c we will I will show you that C 1 dot I will see one display and C one dot display so here this e 1 dot display is a parent I mean the method returned in the parent class c-1 display is the method written in chain 1 so if you save this one will save that and I will execute this one okay sorry which inheritance okay I will run this so you can observe the child one class and appear in class now if you are trying to access the child to Class C you can observe that C to display is the function which is written in child to will get an error because C one is a another class and C 2 is another Claire both are the independent classes okay both are not dependent classes so but the relation between these two classes these two are acquiring the properties from the same same parent so we can access this display function the parent the display function which we are writing from in the parent class that can be accessed with the help of object created by children or child to see I will show you here C 1 and I will create the child to also I mean object for change to see here you can observe here C 1 dot C 2 dot C to display and similarly C 2 dot display so with the help of child 2 object also we can access the parent class yes L 1 class parent class change the class and appearances right so hope you understood this one this is called a hierarchical inheritance hierarchical inheritance now we will see the multiple inheritance so actually this multiple inheritance cannot be supported in Java but here we can directly implement this multiple inheritance in a simple manner right so first we'll write the program so I will save this one will save as a multiple inheritance right so this is called a multiple inheritance now I will change that one so multiple inheritance means so derived class is acquiring the properties from two parent classes so here we should have a two parent classes and then the acquiring the properties of one child CL children so I am writing father father class mother class both are independent classes okay both are independent classes other class mother class right so here I am a child can acquire the properties from both the father and mother so here we can achieve the inheritance by using simple comma separated classes by writing the simple comma separated classes so here the child is inherited from father class comma mother tears so here we can do a multiple number of classes right so this is called a multiple inheritance now by creating the child class say I will show you that mother M display and this is EF display and this is a C display okay so child Care's now by using this the object of a child we can access the methods of both the father and the mother right see C is equal to c1 is equal to change class so c1 is the object with the help of c1 c1 dot C display so this is a display method which is written in child class so c1 dot I am display so which was written in mother class C 1 dot F display which was written in father class so by using the chair as we can access the see child class mother class and the father pairs right so hope you understood this one so multiple inheritance means you one derived class acquiring the properties from multiple base classes so there will be multiple base classes only only one derived class so that should be returned as a comma-separated class names in the base I mean derived class so child acquires the properties I mean child is inherited from father and mother so how to implement by using child followed by the parent I mean parent classes separated with a comma that means a father common a mother right so this is called multiple inheritance right so hope you understood this one let us stop here this is all about the multiple inheritance and hierarchical inheritance so if you are having any doubts regarding these hierarchical and multiple inheritance feel free to post your doubts in the comment section so that I will definitely try to clarify all your doubts and if you real understood my sessions like my sessions share my sessions with your friends and don't forget to subscribe to our channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 20,031
Rating: undefined out of 5
Keywords: sundeep, saradhi, kanthety, java basics, beginners, source code, object oriented, oops, oop concepts, abstraction, inheritance, polymorphism, encapsulation, class, object, method overloading, method overriding, oops example, PYTHON PROGRAMMING, PYTHON FUNDAMENTALS, interpreter, python applications, single inheritance, multilevel inheritance, hierarchical inheritance, multiple inheritance, parent class, child class, base class, derived class, acquiring properties
Id: mhftBEKnw64
Channel Id: undefined
Length: 20min 59sec (1259 seconds)
Published: Sat Oct 12 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.