Welcome to this lecture in this lecture we're going to learn about important characteristics of object
oriented programming that is inheritance.
So first of all what is the inheritance.
So inheritance is a way of creating the new class will make a new class for using details of existing
class.
So we'll have the two classes and they will interact in a way that one classes will be patterned and
another is the class that will inherit take some characters sticks from the prior parent class.
So let's see how this new form classes will be the delay classes or the child from the batting class.
And the first class that is the existing class will be our base class or the bat in the class LSC.
So we have done a couple of calling in the previous leg.
So we have just made a class a Board class that will have the Constructor that will be called automatically
when you just instantiate the object of the class.
And the next one is creating the method of the instance that is sing and dance.
We have created a bunch of instances you're saying the penguin pad or the sparrow.
So let's make a new class over here.
And this will be the Board Class.
We'll just go with the board here and now the four is the metal.
I've already told you that the first method is going to be the unique method that is going to just instantiate
are basically going to get us idea of God.
The constructor and here I am going to say that instead of just assigning some of the attributes are
properties of the classes I'll say board is the class.
So this is going to this give us the information when just instantiating that is this is the board class.
And the next method I'm going to create is in four and I have told you before that the first argument
will be only the self here.
So next year I'll just say print and this is going to be bored.
So we are doing is we're just creating some of the methods over here and now let me says three method
and in this swim only deal is go bird swim.
So these are the masses.
So this is our part in class.
So let me say this is our pattern class which is the bar class.
Let's make another class now and let's see.
This is your style class.
So let's make this style class.
So it is also created by the same class keywords and now as a pattern it is my class.
And if you want to get information that is inherited from this board class the class should be inserted
inside this parenthesis.
So this is the inheritance.
So let's see what we the studio.
We just created the tile class.
And if you want to inherit something from this board class you should be inside this parent is this
if this wasn't a board if it was it was a penguin then it should be inside these panties.
If you want to make use of that court you should be inside these panties.
But in this case you are making bird so I'll just stick with this board.
And now after the bird we have to define the init method again because it is also the new class and
the first method to any class will be the it.
I will literally put four so I'll just say self again and now here what we're going to do is we're going
to print something.
So we're going to print Paro is the class.
Let's see.
This is the class.
The next thing what we're gonna do is we're going to define info for this class too.
And this is going to paint us that this is Penguin not penguin.
It is battered.
And the next thing is a it will this let set on and I'll say self again and this give some information
here.
Ron boy was to OK was this creating a bunch of matter to this better class now.
So I'm told before that while you create the class the next thing you need to do is instantiate the
object of that class that is to make the instance of the class.
So first of all let me say that is Bateau is the name of the parrot.
And let me say this in Estancia this parrot and we don't need to pass anything to this swelling in these
tent sitting because this init method is going to be called and there is nothing except the self.
So self is not to be instantiated or given any barometer to that that means it was a skull spattered.
So let's say this is battered but if I say battle and if you just remember from the previous lecture
if you want to call any metal of that glass if should be done from the object dot and just say I'll
just call in for OK and the next is battle Dot.
Let's see.
I want to call a swim to save this and place a five.
So let's see what we have justice done here is we're not getting any either.
So if you this remember we're just creating these stanzas.
We are just calling the info method which is the method inside here.
But if you see it swim can you see swim anywhere over here.
We're just making these stances we are not making instances of this as if it was the Bard then we don't
have any problem because because info is also inside the board.
Swim is also inside the bird.
In this case we'll see that.
Okay.
Go bird swim board boards a glass.
So that is perfectly fine.
But here we're not dealing with the board but we are dealing with a parrot and still we're not getting
in either.
We're getting go bird swim.
Although this method this swim method is not inside this parrot.
So this is the one part of everything so what you just did was we just had the inheritance that means
everything that is inside this bird plus suitable also inside these better plans.
So what we just did was we just copied everything from this and we just copied over here.
So any method is not going to be copied but except we need method.
Everything is going to be copied.
So this swim method info method will be copied from the bird class to this better plus.
So that means we can call this swim method it's if it is inside this better class although it is not
in the pattern class but we just did inheritance that means we can call this swim method.
So that is the importance of this inheritance in object oriented programming.
So next thing I want to show you here is the super method.
So if I say super and if I just call this in it let's see what is happening over here.
Let's save this first and present five then it is saying bodies the class parrot is a class parrot global
swim.
So let's see.
Let's put it right here and so you.
What is happening here.
So first of all what we did was we just created the battered object so no problem over here.
We're getting this init method to be called now because we have this in instantiating this.
So if you're the scholar in book this init method which is the constructor of this battered class we
have this super meter.
So support is just pointing to this superclass that is the pattern class.
So we are referring from these super that these super suit.
Call this board class and this init method is invoked that means that this print bodies class is going
to be in work.
What that means if you see here where the board is the class Well the first thing that is going to be
printed because this is the first method that is invoked by this statement.
After that it will go here and it will print parodies the class in the next statement which is over
here.
Better it is the class.
And after that it is invoked.
It was a scholar imprimatur of this battle which is this.
And it will just print parrot which you can see over here.
And last is swim which is obviously not in the parrot class but we have the inheritance that means we
can also call the swim method of the parent class and it is giving us information of Go board swim seats
right or will go board swim.
So if you see here this super method is going to this deal with the super or a betting class which in
this case is board.
And the one way to this fine child class in batting classes if you just make this class and inside the
parenthesis if you have any other class this is going to be your superclass or a bad in class.
And this class which is going to inherited that parent class is going to be that size class.
So this is the inheritance which we just learned about here.
So this very important paradigms of the object oriented programming and this is important things to
learn.
So we'll see how to work with these and work with the network interface while we hack and we just do
some of the ones this stops in the Python programming 6 and c in the next one.