27 Implementation of Multiple Inheritance Class in Python programming.

preview_player
Показать описание
So first of all what is multiple inheritance.

So the ability of a class to inherit from more than one class is called multiple inheritance.
and in

Python A class can inherit from more than one class.

So let's see an example which shows us how to inherit from my table classes.

Now I will be using the this example which I have already shown you in the video.
where I have shown

you inheritance in python.
So that is at last call the polygon which is a superclass .
and the other two

classes are triangle class and the rectangle class .
which are the subclasses.

And these two classes are inheriting from the polygon class.

And I have also one more python file which is main dot P Y.

And this main dot P Y.

I'm just importing these two rectangle and trying new class. and creating an instance out of them and

then setting the value of width and height.

And then we are printing that area of the rectangle and the triangle.

So if you haven't seen the last two videos just watch those videos. because I will be using the same

code in order to show you how to use multiple inheritance.

So let's get started.

So what I'm going to do is I'm going to create a new python file here . and I'm going to name my file as

a shape . and I'm going to use this shape dot

P Y to create a class called Shape.

So let me create class quickly and I'm going to name it the shape and this method.

I'm going to define a private variable called Color . and I'm going to initialize it with the value none.

And then I'm going to define the setter and getter for this color attribute. so let's define those

so now we have to define the setter and getter for this color attribute.

Now if you remember what I told you about in inheritance. and that is when ever you want to do inheritance

between a superclass and a subclass. there is a relationship between the subclass and the superclass.

So rectangle is our shape and triangle is also a shape.

So that means we can also use this shape class as the superclass in the rectangle and that triangle

classes.

So let's use that shape class into the rectangle and triangle class as the superclass.

So first of all I'm going to import this shape class from the shape files.
so let's import this and same.

I will do in a triangle class also.

And now how to inherit from multiple classes into our subclasses.

**************************************************************************
please like and follow us in Facebook and Instagram.

Рекомендации по теме