1 00:00:00,610 --> 00:00:06,020 Biton is one object oriented programming language, so it supports inheritance. 2 00:00:06,370 --> 00:00:11,200 So this video will be will be discussing what is Python inheritance? 3 00:00:12,290 --> 00:00:20,000 So it refers to defining a new class with little or no modification to an existing class, so a new 4 00:00:20,000 --> 00:00:26,690 class will get created from the existing class with the with some changes, or it may not be having 5 00:00:26,690 --> 00:00:27,720 any change at all. 6 00:00:28,070 --> 00:00:33,590 That new class is called the derived class, also known as the child class and the class from which 7 00:00:34,040 --> 00:00:39,210 one of the classes from which it inherits will be known as a base class or the parent class. 8 00:00:39,680 --> 00:00:40,940 So just consider this one. 9 00:00:40,940 --> 00:00:43,390 We are having multiple different types of inheritances. 10 00:00:43,490 --> 00:00:45,240 How many types of inheritance are there? 11 00:00:45,470 --> 00:00:46,450 So five types up. 12 00:00:46,580 --> 00:00:47,510 What is the first one? 13 00:00:47,780 --> 00:00:49,160 There is a single inheritance. 14 00:00:49,310 --> 00:00:53,380 Means what means one best class and one derived class. 15 00:00:53,390 --> 00:00:55,350 So that is known as a single inheritance. 16 00:00:55,790 --> 00:00:58,000 So here you are having the multiple inheritance. 17 00:00:58,010 --> 00:00:58,940 What does it mean? 18 00:00:59,200 --> 00:01:01,190 Will it be having multiple best classes? 19 00:01:01,190 --> 00:01:07,390 Not only do we can have more than two also will be having multiple classes, but one direct class. 20 00:01:07,610 --> 00:01:12,020 So this particular class will inherit the properties from all the best classes. 21 00:01:12,590 --> 00:01:14,480 This is our hierarchical inheritance. 22 00:01:14,480 --> 00:01:20,080 Only one best class and multiple derived classes here have shown three different classes. 23 00:01:20,210 --> 00:01:21,290 It may be two also. 24 00:01:21,290 --> 00:01:22,960 It may be five or six, maybe seven. 25 00:01:22,970 --> 00:01:26,870 Also here to having the middle level inheritance. 26 00:01:26,870 --> 00:01:29,940 What is the meaning of this multilevel inheritance? 27 00:01:30,380 --> 00:01:31,730 So this is the best class. 28 00:01:32,150 --> 00:01:38,930 There is a direct class and for the C being the best class and sees the direct class here when having 29 00:01:38,930 --> 00:01:41,630 this hybrid inheritance, what does it mean? 30 00:01:41,660 --> 00:01:44,040 What is the meaning of this hybrid inheritance? 31 00:01:44,390 --> 00:01:46,430 So here you see this is a one best class. 32 00:01:47,000 --> 00:01:48,560 These are the direct classes. 33 00:01:48,740 --> 00:01:55,430 And now for this D, this B and C are the best classes and these the direct class. 34 00:01:55,640 --> 00:01:59,510 So that is known as that is known as hybrid inheritance. 35 00:01:59,520 --> 00:02:06,770 So it is actually nothing, but it is hierarchical, multiple inheritance, it is hierarchical, multiple 36 00:02:06,770 --> 00:02:08,170 inheritance in the soil. 37 00:02:08,170 --> 00:02:13,660 Also you can have another combination that is that is of a multiple and hierarchical inheritance. 38 00:02:13,820 --> 00:02:19,660 So from multiple based classes, one day class and from one class to the multiple derived classes. 39 00:02:19,660 --> 00:02:20,930 So that can also happen. 40 00:02:21,200 --> 00:02:24,210 That is known as multiple hierarchical inheritance. 41 00:02:24,710 --> 00:02:28,420 So here to discuss what are the different types of inheritance, as are there. 42 00:02:28,580 --> 00:02:31,190 So let us go for one practical demonstration. 43 00:02:31,310 --> 00:02:37,640 For the better understanding in decision, we shall discuss inheritance and polymorphism, which will 44 00:02:37,640 --> 00:02:42,980 be observed in Python in object oriented programming here to define one class. 45 00:02:43,010 --> 00:02:44,660 So here you have defined one class. 46 00:02:44,660 --> 00:02:46,180 The name of the class is my word. 47 00:02:46,700 --> 00:02:47,830 This is the constructor. 48 00:02:48,230 --> 00:02:49,250 These are what type? 49 00:02:49,250 --> 00:02:52,280 That is one method and can swim is another method. 50 00:02:52,640 --> 00:02:53,090 The method. 51 00:02:53,090 --> 00:02:53,540 What is up. 52 00:02:53,540 --> 00:02:54,070 It is simple. 53 00:02:54,080 --> 00:03:00,800 We have just put one step statement there and here we are having another class that is known as my pinguin, 54 00:03:01,130 --> 00:03:03,050 which is inheriting my board. 55 00:03:03,440 --> 00:03:05,950 C my my word you have defined here. 56 00:03:05,960 --> 00:03:06,380 So let me. 57 00:03:07,400 --> 00:03:12,430 So here the class has been defined and my pinguin is inheriting my part. 58 00:03:13,160 --> 00:03:18,980 So like of a java here we need to write extensor or any other key words just within this bracket were 59 00:03:18,980 --> 00:03:24,440 mentioning the respective classes in the classroom which will be mentioned within this bracket, will 60 00:03:24,440 --> 00:03:27,290 be known as a base class, also known as a super class. 61 00:03:27,530 --> 00:03:30,080 And this is our direct class or subclass here. 62 00:03:30,470 --> 00:03:35,900 So in case of Python, the class inheritance will be written using this particular syntax. 63 00:03:36,560 --> 00:03:42,860 So this my penguin is having the respective constructor and here you are calling the best class constructor. 64 00:03:42,860 --> 00:03:48,500 So this class will be called by the super method and it's constructor is always understood, understood 65 00:03:48,500 --> 00:03:50,330 and understood, understood method. 66 00:03:50,810 --> 00:03:57,410 So that is a Bicyclers constructor calling and then one statement to get printed and who is this and 67 00:03:57,410 --> 00:03:58,700 can can run. 68 00:03:58,700 --> 00:04:02,120 So these are the other two methods in this might be in Greenglass. 69 00:04:02,570 --> 00:04:07,940 So just remember in my board, along with the constructor, we are having what type and can swim. 70 00:04:08,390 --> 00:04:15,320 And in case of my pinguin we're having this constructor and along it we are having who is this and can 71 00:04:15,320 --> 00:04:15,710 run. 72 00:04:15,830 --> 00:04:20,210 So these two other methods are there, but defining one pinguin class object. 73 00:04:20,210 --> 00:04:22,310 So it has been defined in a very simple way. 74 00:04:22,640 --> 00:04:27,230 So that means we are having this my pinguin and then we are having the p.g. 75 00:04:27,230 --> 00:04:28,450 One is the object name. 76 00:04:29,000 --> 00:04:29,570 So we. 77 00:04:29,660 --> 00:04:31,130 You want what type. 78 00:04:31,130 --> 00:04:34,100 This particular what type was defined in the class. 79 00:04:34,100 --> 00:04:39,560 That is my part as my has got inherited into my pinguin. 80 00:04:39,560 --> 00:04:44,570 So my word methods can be accessed from this might be an object. 81 00:04:44,900 --> 00:04:48,560 So that's why you want what type can be executed. 82 00:04:48,950 --> 00:04:51,770 But having p.g one having B.G. one dot. 83 00:04:52,040 --> 00:04:53,150 Who is this. 84 00:04:53,180 --> 00:04:58,670 So it is defined in case of my pinguin you can easily find in my opinion who is this is defined. 85 00:04:59,090 --> 00:05:06,800 But having this p.g one dot can see it having p.g one dot can run did you can see was defined in my 86 00:05:06,800 --> 00:05:08,000 word class and p.g. 87 00:05:08,010 --> 00:05:09,110 One dot can run. 88 00:05:09,380 --> 00:05:11,090 This can can run was defined. 89 00:05:11,090 --> 00:05:11,650 It might be. 90 00:05:12,430 --> 00:05:15,760 That is what type and can swim we are inheriting. 91 00:05:16,180 --> 00:05:20,620 We're getting this one from the best class that is my bird, because there they were defined. 92 00:05:22,040 --> 00:05:28,790 So now let me go for the execution my class constructed is executing my penguin class constructor is 93 00:05:28,790 --> 00:05:29,330 executing. 94 00:05:29,330 --> 00:05:32,960 You can easily find that here you have called the Bicyclers constructor. 95 00:05:32,960 --> 00:05:34,930 So that's why the control has gone to this. 96 00:05:35,240 --> 00:05:41,720 So my world class constructor is executing has got printed at first, then my Pinguin class constructor 97 00:05:41,720 --> 00:05:42,530 is executing. 98 00:05:42,530 --> 00:05:44,710 So that string has got printed. 99 00:05:45,080 --> 00:05:46,070 So now we called. 100 00:05:46,080 --> 00:05:46,760 What type. 101 00:05:46,880 --> 00:05:50,420 So what type is having the string that is ironbound. 102 00:05:50,510 --> 00:05:51,940 So that has to be printed. 103 00:05:52,640 --> 00:05:53,720 That has got printed. 104 00:05:54,080 --> 00:05:55,010 I'm pinguin. 105 00:05:55,010 --> 00:05:57,820 So now next method we call this who is this. 106 00:05:58,160 --> 00:05:59,300 So I am pinguin. 107 00:05:59,300 --> 00:06:05,900 So that string has got printed next we went for this can seem so consumers having this string to be 108 00:06:05,900 --> 00:06:09,250 printed that is I can swim so I can swim has got printed. 109 00:06:09,440 --> 00:06:12,750 Now we are having this can run and I can run faster. 110 00:06:13,010 --> 00:06:15,730 So in this way this particular string has got printed. 111 00:06:16,070 --> 00:06:21,860 So using this example we have shown you how inheritance can be implemented in Python. 112 00:06:22,550 --> 00:06:24,440 So let us go for another example here. 113 00:06:24,830 --> 00:06:27,560 But having one class, the name of the class is my Barat. 114 00:06:27,920 --> 00:06:30,880 And here we are having can fly and can swim. 115 00:06:31,340 --> 00:06:37,130 So obviously Barat can fly so bird can fly, but parrot cannot seem so parrot can't swim. 116 00:06:37,370 --> 00:06:42,690 I'm having another class that is my penguin which is having to make the same simply because I easily 117 00:06:42,710 --> 00:06:47,800 find that they can fly self and they can swim self. 118 00:06:47,810 --> 00:06:51,290 So you see we're having the same problem different here also. 119 00:06:51,770 --> 00:07:00,140 OK Narcy so diff can fly itself so Pinguin cannot fly and they can swim self-aware, having penguins 120 00:07:00,160 --> 00:07:00,800 can swim. 121 00:07:01,460 --> 00:07:05,420 So now we are having one common interface that is flying bird test. 122 00:07:05,690 --> 00:07:11,480 OK, so I'm going for this bird that can fly and also Bertaud can swim. 123 00:07:12,730 --> 00:07:18,940 So here in this particular method, we're just passing this part as input parameter and we are calling 124 00:07:18,940 --> 00:07:21,870 this board that can fly and Bertaud can seem. 125 00:07:22,300 --> 00:07:28,530 So here we have to find one class object, my class object, and one might be in class object. 126 00:07:28,960 --> 00:07:31,450 So we're calling this flying test. 127 00:07:31,460 --> 00:07:37,600 We're calling this flying test with this birthparent that is which is a class object and part penguin, 128 00:07:37,600 --> 00:07:39,230 which is a penguin class object. 129 00:07:39,700 --> 00:07:43,430 So what will happen when we are passing this birthparent? 130 00:07:43,630 --> 00:07:45,360 So that is a better class object. 131 00:07:45,730 --> 00:07:51,080 So that particular subject that can fly and class object that can you get executed. 132 00:07:51,400 --> 00:07:58,180 So as a result of that, this can fly and this can swim, the respective body will get executed and 133 00:07:58,180 --> 00:08:00,030 respective strings are going to get printed. 134 00:08:00,640 --> 00:08:05,770 But when we were passing this board, Pinguin, which is the MIT penguin class object as input parameter 135 00:08:05,770 --> 00:08:07,260 to this flying test. 136 00:08:07,670 --> 00:08:13,830 So in that case, this board can fly and Bart can swim, will be operated on, this being my being in 137 00:08:13,840 --> 00:08:14,610 class objects. 138 00:08:14,980 --> 00:08:17,140 So in that case, what will happen regarding this? 139 00:08:17,140 --> 00:08:20,980 Penguin cannot fly and penguins can swim in case of flying. 140 00:08:20,980 --> 00:08:23,890 But this part penguin, I think is off flying. 141 00:08:23,890 --> 00:08:28,450 But this parrot would have been better, can fly and parrot cannot see him. 142 00:08:28,870 --> 00:08:35,350 So you can find that how these classes are having their respective objects and objects are being passed 143 00:08:35,350 --> 00:08:41,960 to this flying test and respectively, the respective can fly and can see method will get executed. 144 00:08:42,400 --> 00:08:48,550 So in this particular session, we have discussed what is the how to implement inheritance, how to 145 00:08:48,550 --> 00:08:52,970 do the polymorphism in our python, in what object oriented programming. 146 00:08:53,530 --> 00:08:54,760 Thanks for watching this video.