WEBVTT

00:00.900 --> 00:08.400
Hey, in this session, we will discuss about inheritance, so inheritance allows us to create a new

00:08.400 --> 00:12.780
child clause which is based on the existing betting class.

00:13.380 --> 00:20.760
In this particular case, the child class will have all the attributes and methods of the best in class,

00:21.030 --> 00:25.260
which can be modified internally in the first class as well.

00:25.860 --> 00:27.430
So what does this mean?

00:27.870 --> 00:35.940
So here inheritance is a way to form new classes using classes that has already been defined.

00:36.270 --> 00:44.570
So let's say we have created a class person so a person will have certain attributes and methods.

00:44.850 --> 00:51.720
So let's see the attributes related to the person I name, age, address.

00:52.680 --> 00:57.880
Now, the methodology to the person would be, let's say dog, walk, eat.

00:58.380 --> 01:03.600
Now, these are Gendron methods and general attributes related to a person.

01:04.050 --> 01:14.520
Now, whenever I'm creating an employee or a doctor or an engineer in that particular case, will I

01:14.520 --> 01:21.630
be writing the method and the attributes which are pre existing again?

01:22.080 --> 01:28.650
So ideally, what I should be doing is if I don't really know about inheritance, I would be creating

01:29.190 --> 01:36.810
an employee class and my employee class will be having certain attributes, for example, name, age,

01:36.810 --> 01:43.520
address of the person, and additionally something which is specific to employees such as their employee

01:43.520 --> 01:46.770
and their salary.

01:47.010 --> 01:52.520
And the methods would be, let's say, work or travel to office, come back from office.

01:52.770 --> 01:55.140
These are something related to the employee.

01:55.530 --> 01:59.070
Now, whenever I am creating a doctor, what will happen now?

01:59.070 --> 02:05.130
The doctor will have something like diagnose, then perform a surgery.

02:05.310 --> 02:09.300
And apart from that, it will again have the ones which will probably present.

02:09.310 --> 02:09.640
Right.

02:09.840 --> 02:16.020
So, for example, name, address and eat, sleep, work, because doctors will also perform all the

02:16.080 --> 02:19.770
actions and religious rituals are performed by a person.

02:20.100 --> 02:31.080
So here what we get to see is that whatever behavior was present in a person actually comes inside or

02:32.250 --> 02:38.100
engineer or a doctor or a student or a human being, anything like any such activity.

02:38.740 --> 02:46.410
Right now what we are doing is when we are creating this specific class, such as doctor here, we are

02:46.740 --> 02:49.410
adding a few methods additionally.

02:50.400 --> 02:50.690
Right.

02:51.030 --> 02:58.510
So basically it has different methods and attributes from the parent class, the art of the present,

02:58.530 --> 03:00.240
which would be present in to the better.

03:00.510 --> 03:03.180
So I don't create these methods.

03:03.180 --> 03:05.460
Again, I just Dellec that.

03:05.460 --> 03:07.000
Okay, you are, doctor.

03:07.020 --> 03:13.620
So this class of doctor will contain all the methods which are specific to Bochner and also inherit

03:13.620 --> 03:19.890
all the methods and attributes which are already present and created when we created a person so that

03:19.890 --> 03:22.580
we don't have to create things again and again and again.

03:23.640 --> 03:24.020
Right.

03:24.480 --> 03:27.570
Similarly, even I have created a doctor.

03:27.600 --> 03:30.930
Now this doctor is actually, let's say, a neurosurgeon.

03:31.350 --> 03:38.340
So the neurosurgeon will have some more specific details and some more specific tasks which he will

03:38.340 --> 03:38.790
perform.

03:39.150 --> 03:44.750
So now this class will inherit from the person class.

03:44.760 --> 03:46.850
Also, I'm from the doctor glassless.

03:47.760 --> 03:48.140
Right.

03:48.350 --> 03:50.650
So this can create a change.

03:50.650 --> 03:56.610
So we can what we can do is whenever I'm creating a particular class, if I need something which needs

03:56.610 --> 04:01.800
to be repeated, if I need certain behaviors and attributes which are already present in some other

04:01.800 --> 04:05.510
class, I can simply inherit from that class.

04:05.610 --> 04:07.560
I mean, I inherited from that class.

04:07.560 --> 04:14.880
The class from which I am inheriting is for the best class or the better in class and the class which

04:14.880 --> 04:22.740
I am inheriting to the new class of the day and creating is called Giedd Class or derived class.

04:24.180 --> 04:29.660
OK, so this is the basic concept behind inheritance.

04:30.180 --> 04:38.860
Now let us go back and try to create this thing and implement this thing.

04:43.500 --> 04:48.600
So let us go ahead with inheritance.

04:53.700 --> 04:57.250
Now, here's what we need is we are creating a new middle class.

04:57.270 --> 05:00.780
OK, so my class is animal.

05:01.200 --> 05:03.270
Now, what does an animal do?

05:03.300 --> 05:07.020
This is my divine creator in it.

05:08.000 --> 05:16.950
OK, this is the initialization it takes self and it to

05:25.650 --> 05:27.570
create an animal created.

05:28.050 --> 05:32.280
Now, let me create another method and say this.

05:32.610 --> 05:34.070
This is animal created.

05:34.080 --> 05:37.860
Another one is say.

05:40.950 --> 05:42.420
This one is

05:47.430 --> 05:49.080
who am I?

05:49.590 --> 05:49.930
OK.

05:50.400 --> 05:53.650
And this says that this is animal.

05:54.120 --> 05:56.310
Next I am creating.

06:02.570 --> 06:02.870
E!

06:06.100 --> 06:07.540
And what does it do?

06:07.570 --> 06:14.650
It says it OK, now I'm creating another class now.

06:14.680 --> 06:18.670
This class is what this class would be, a dog class.

06:19.060 --> 06:21.130
OK, now I'm creating a dog class.

06:21.130 --> 06:23.060
Now let's create the dog class.

06:23.590 --> 06:31.990
So I said, OK, now I want this dog class to inherit these initialization.

06:32.200 --> 06:35.170
Who am I this eat from the animal class.

06:35.200 --> 06:40.390
OK, I want this to get all the stuff which is present in my animal class.

06:40.630 --> 06:44.640
It because dog is what dog is up animal.

06:44.650 --> 06:47.310
So I want those things to be already presented.

06:47.320 --> 06:48.970
I don't want to write it down again.

06:49.330 --> 06:57.640
So what I simply do is I will tell it like you need to inherit stuff from animal class.

06:58.250 --> 07:04.480
OK, now this understand when I write it inside the brackets, it's understanding that I need to inherit

07:04.480 --> 07:05.600
from this animal class.

07:06.190 --> 07:14.640
Now, in the initialization, I would say that dog has been created by, say, dog created and I'm asking

07:14.650 --> 07:15.200
where am I?

07:15.220 --> 07:20.170
So I'll tell it that, OK, this is a dog, OK?

07:20.560 --> 07:25.230
And I create another function which is bark, OK?

07:25.540 --> 07:33.010
And when it says barking, it's where it will say, well, OK, so this is what I am doing now.

07:34.900 --> 07:35.980
What have we done now?

07:35.990 --> 07:37.750
We have created an animal class.

07:38.110 --> 07:42.880
We have created a dog class in animal class we have initialization.

07:42.880 --> 07:50.680
So when an instance of animal would be created, it will say animal created, then we will create the

07:50.680 --> 07:51.310
object.

07:51.310 --> 07:53.200
I'm from on top of that object.

07:53.200 --> 07:55.260
We will then where might will say animal.

07:55.320 --> 07:57.520
Then we will ask it to eat.

07:57.760 --> 07:58.870
It will say eating.

07:59.140 --> 08:05.350
When we create an object of dog it will say dog created when we run this.

08:05.350 --> 08:09.070
Who am I from the dog object it will say dog.

08:09.310 --> 08:16.270
And when we say bark it will say OK so let us run this one.

08:16.270 --> 08:17.470
So it has been run.

08:17.830 --> 08:21.020
Now what will create will create an object of the dog.

08:21.250 --> 08:27.040
So we will see dog one is equal to dog.

08:27.670 --> 08:30.370
So we are creating an object of the dog.

08:30.370 --> 08:33.700
Plus what happens now when I run this.

08:34.000 --> 08:39.340
It says that dog created ok.

08:41.610 --> 08:46.080
See, this is dog and the same dog created.

08:46.450 --> 08:49.570
Now let's make a little slight change.

08:49.590 --> 08:51.490
OK, now what do you see?

08:51.640 --> 08:59.460
I asked that whenever you are initializing the dog, initialize the animals.

08:59.860 --> 09:02.950
So what we can see from the animal class.

09:03.600 --> 09:09.120
OK, then, because we are calling the animal Glaswegians, the animal that we were talking about,

09:09.120 --> 09:14.190
any object, then we would have referred to the object itself here.

09:14.230 --> 09:22.130
OK, so we are seeing animal dot in it and inside this we are putting.

09:22.950 --> 09:25.180
OK, now see the difference.

09:25.230 --> 09:30.890
OK, so when we done this just a moment I'll have to run this again.

09:31.590 --> 09:33.840
When we done this we animal created.

09:33.840 --> 09:34.540
Both created.

09:34.860 --> 09:36.320
Now see the difference.

09:36.330 --> 09:42.420
OK then we wrote only this in it and only this particular in it.

09:42.420 --> 09:45.150
We have not written this particular statement.

09:45.420 --> 09:49.290
It did not run the initialization of the animal flush.

09:50.220 --> 09:57.120
OK, if you want to run the initialization of the animal class also, then you will have to run the

09:57.120 --> 09:59.600
animal in here, OK?

09:59.880 --> 10:02.910
Otherwise it will run only initialization for the book.

10:03.630 --> 10:08.130
OK, now let's go for the next thing we say.

10:08.130 --> 10:09.960
Dog one dot.

10:13.840 --> 10:18.340
I OK, and she wondered, why am I so what does it say?

10:18.350 --> 10:23.900
It says Dog, OK, now why is it saying Who am I?

10:23.910 --> 10:30.590
Because it has inherited it would have inherited this particular who am I now?

10:30.590 --> 10:36.050
Because this is present here now we have overcome this.

10:36.480 --> 10:39.150
OK, now this would have came down here.

10:39.170 --> 10:40.180
Now let me do one thing.

10:40.190 --> 10:43.940
Let me just comment this week.

10:44.450 --> 10:53.930
Now, when I go this and I run this again, I run this again and I create this object again and I run.

10:53.930 --> 10:59.120
Bob wondered, who am I now I get and what do I why do I get animal?

10:59.130 --> 11:02.660
Because this is inherited.

11:02.670 --> 11:05.030
So this comes down here.

11:05.780 --> 11:10.930
So it as it is assuming that when I am running, Bob wondered why am I.

11:10.940 --> 11:13.460
Because there is nothing as women here.

11:13.700 --> 11:17.320
So it is getting the metal from the base class.

11:17.660 --> 11:27.770
But when we come this, when we actually define who am I inside the child plus then it will give preference

11:27.770 --> 11:31.240
of priority to the Who am I present in detritus.

11:31.640 --> 11:35.580
So whatever was written in this animal class actually get over it.

11:35.860 --> 11:38.930
And when we are running, who am I from the book.

11:38.930 --> 11:41.140
One that is the object of the dog class.

11:41.330 --> 11:43.760
It will run whatever is present here.

11:43.770 --> 11:46.910
So if I run this then it will say dog.

11:47.330 --> 11:52.700
OK, next, if I say let's say dog one dog

11:55.880 --> 11:59.870
eat dog I say eat.

12:00.170 --> 12:01.010
So what happens.

12:01.010 --> 12:08.000
It says eating because it has inherited this method from the parent class because it does not present.

12:08.210 --> 12:09.470
So it will run whatever it was.

12:09.470 --> 12:13.880
But as an independent class it now again same thing applies to the bark.

12:14.390 --> 12:25.430
OK, so when I say dog one don't bark, then it will say because this is a new method which we have

12:25.430 --> 12:28.250
created in the dog and that is a Gigas.

12:28.550 --> 12:30.670
So now you understand what is happening.

12:30.680 --> 12:39.080
So basically what we are doing is if we have any method which was in the best class and is not present

12:39.080 --> 12:45.830
in the jungle, then it will run whatever it is, and basically it will run that method of method from

12:45.830 --> 12:46.550
the base class.

12:46.880 --> 12:52.400
If you have over it in the method in the gym class or you have newly created the method method in the

12:52.400 --> 12:55.090
gikas, then it will run it from each class.

12:55.170 --> 12:56.410
It's as simple as that.

12:56.420 --> 12:57.500
Nothing complicated it.

12:57.900 --> 13:05.870
OK, so next thing, what we will be learning about is polymorphism.

13:05.870 --> 13:09.890
So let's talk about this in the next session.
