1 00:00:00,060 --> 00:00:06,600 So I welcome you again to the next session on Happy Learning, and we are going to cover inheritance 2 00:00:06,600 --> 00:00:10,540 in C++, that's the topic we are covering on this unit. 3 00:00:10,560 --> 00:00:12,120 So let's jump on to that topic. 4 00:00:12,220 --> 00:00:19,140 So talking about inheritance, inheritance means the capability of a class to derive the properties 5 00:00:19,140 --> 00:00:21,340 and characteristics from another class. 6 00:00:21,360 --> 00:00:29,130 So suppose we have two classes classes a class and Class B OK, and Class B want to get some properties 7 00:00:29,130 --> 00:00:35,280 from Class A. That is normative so that properties can be their members or even member functions. 8 00:00:35,310 --> 00:00:37,440 So why we are using an inheritance? 9 00:00:37,440 --> 00:00:43,570 Inheritance is one of the most important feature in the C++ order in the world of object oriented programming. 10 00:00:43,600 --> 00:00:48,210 But why we are using inheritance is to enhance that using feature. 11 00:00:48,210 --> 00:00:54,540 So instead of writing everything from scratch, which is already defined in this program, if we can 12 00:00:54,690 --> 00:01:00,570 reuse the existing components and create new components from those existing components, that will be 13 00:01:00,570 --> 00:01:03,540 more equally vital in order to promote that. 14 00:01:03,540 --> 00:01:09,870 In order to make sure that you can reuse all the components, all the glasses, all the objects, all 15 00:01:09,870 --> 00:01:13,110 the functions are all that values are data variables. 16 00:01:13,110 --> 00:01:18,090 In a program, we can use the feature called inheritance that is too important garden type you need 17 00:01:18,090 --> 00:01:21,840 to know while we are talking about inheritance in C++ learning. 18 00:01:21,840 --> 00:01:24,600 Superclass OK, and none of this subclass. 19 00:01:24,600 --> 00:01:29,920 So a subclass is a class that inheritance inherit properties from another class. 20 00:01:29,940 --> 00:01:36,470 So suppose there is a class card, Class E and Class another class card, Class B and Glass B's. 21 00:01:36,480 --> 00:01:43,110 Inheriting some properties from Class A, then Class B is called the subclass of class, so top class 22 00:01:43,110 --> 00:01:47,190 is also called deriving a class, then next class superclass. 23 00:01:47,190 --> 00:01:52,160 Suppose that is a class which is a reference class for a sub class. 24 00:01:52,170 --> 00:01:59,220 That means that our subclass is inheriting some functions and variables from other superclass. 25 00:01:59,220 --> 00:02:01,770 So that class is called superclass. 26 00:02:01,890 --> 00:02:05,370 So we can see a good example of inheritance all here. 27 00:02:05,430 --> 00:02:08,030 Bensouda, the case of three makers. 28 00:02:08,040 --> 00:02:14,940 OK, I have three acres, so I have created three classes for these three vehicles and each class contained 29 00:02:14,940 --> 00:02:16,860 its own member functions. 30 00:02:16,920 --> 00:02:18,940 But I know very similar aspect, right? 31 00:02:18,960 --> 00:02:20,100 It's a class guard. 32 00:02:20,100 --> 00:02:26,350 Bess and B+ Best will contain function to calculate that amount regard to Philadelphia. 33 00:02:26,370 --> 00:02:33,570 So that is a full on function capacity function to get how much fuel that particular vehicle can hold, 34 00:02:33,720 --> 00:02:35,210 and they decided the function. 35 00:02:35,220 --> 00:02:42,180 We just can't apply brakes, which will specify the amount of effort or effort required to apply the 36 00:02:42,180 --> 00:02:42,530 brakes. 37 00:02:42,540 --> 00:02:49,130 So even if it is three different classes, these three vehicles can use these functions right. 38 00:02:49,180 --> 00:02:52,590 See Class Bess have all these three facilities. 39 00:02:52,590 --> 00:02:58,440 Similarly, Blast God should also help you out of my own capacity and apply brakes because this is common 40 00:02:58,440 --> 00:03:00,420 to all the classes and also class. 41 00:03:00,810 --> 00:03:06,390 Even if it is a trap, it should be able to find the amount of fuel required, capacity required and 42 00:03:06,390 --> 00:03:08,900 how much I would be required to apply the brakes. 43 00:03:08,940 --> 00:03:12,830 So all these classes require these three functions. 44 00:03:12,840 --> 00:03:20,520 So instead of making this class, each class a new function for the same purpose, so the buses are 45 00:03:20,580 --> 00:03:21,360 safe, right? 46 00:03:21,480 --> 00:03:27,900 So instead of making three three different functions on each class, we can be sure that we create a 47 00:03:27,900 --> 00:03:29,730 new class car class maker. 48 00:03:29,730 --> 00:03:33,220 So that class very good contains all these three functions. 49 00:03:33,240 --> 00:03:38,280 So here you can see that if you allow more designer capacities that apply brakes is there, and what 50 00:03:38,280 --> 00:03:46,380 happens is class best car and truck can get this function from glass very good and use it whenever required. 51 00:03:46,410 --> 00:03:52,560 So instead of writing the same functions three times in each of these class, I have created a separate 52 00:03:52,560 --> 00:03:58,110 super class which is having all these functions and all subclasses or derived classes. 53 00:03:58,110 --> 00:04:03,270 Best Scott and Truck gets the functions when nobody forms to use. 54 00:04:03,280 --> 00:04:06,930 So here you can see an inheritance diagonal class. 55 00:04:06,960 --> 00:04:14,190 Meg Lees, the superclass and Buska and Track are that subclasses and the adding head hitting see that 56 00:04:14,430 --> 00:04:20,100 this is getting see that this is getting this function from the Ebo class. 57 00:04:20,130 --> 00:04:23,790 These three Genzel class buses inheriting B-Class vehicles. 58 00:04:23,790 --> 00:04:25,280 So this is that diagonal. 59 00:04:25,330 --> 00:04:32,220 So what I who is that superclass that will be on the top and the subclass will be on the bottom? 60 00:04:32,220 --> 00:04:37,320 And yeah, auto will be like this subclasses inheriting the superclass. 61 00:04:37,320 --> 00:04:43,380 So there should be an arrow from superclass to stop fastener drums up class to class, but instead we 62 00:04:43,380 --> 00:04:49,770 will be putting an arrow from superclass to subclass how that's how you would an inheritance bag. 63 00:04:49,860 --> 00:04:57,210 So how you can implement inheritance in C++ is our next topic, and there is a specific syntax dedicated 64 00:04:57,210 --> 00:04:59,870 for implementing inheritance in C++, so. 65 00:05:00,010 --> 00:05:05,350 Here is the syntax I have given for you, so class during this class, then you have to give this up 66 00:05:05,360 --> 00:05:05,990 class name. 67 00:05:06,010 --> 00:05:11,850 Then you have to put this dodge symbol up and down dog, and then you have to put the access mark, 68 00:05:11,860 --> 00:05:13,300 then base class name. 69 00:05:13,300 --> 00:05:20,110 So you have three access Marzia, Public Protector and private and you getting heritage superclass in 70 00:05:20,110 --> 00:05:26,080 three ways that is Public Protector and private each have a different speciality so that we will be 71 00:05:26,080 --> 00:05:27,070 discussing shortly. 72 00:05:27,070 --> 00:05:33,100 So after you write this index, we will be writing the body of the class and inside that basis, followed 73 00:05:33,100 --> 00:05:34,240 by a semicolon. 74 00:05:34,420 --> 00:05:38,560 So you have if supposing I want to inherit a class guard Class B.