Hi everybody.
Welcome back.
In this video we will discuss Object Oriented Programming inheritance.
Inheritance allows us to create a general or basic class and reuse and extend it to more and other classes
also.
It allows us to meet our Python code in more efficient
inheritance.
Example let's create superclass and two classes as example fruits class stimulate truth superclass class
banana subclass of the superclass fruit Apple is subclass of subclass fruits let's augment our job it
on notebook at the last.
Could we use in as a constructor video class which is class user data age equals zero name.
Equal none.
Let me underscore any double underscore self.
Name and age.
Salvador name.
Equal name.
That age equal age.
We want to create another class called for numbers.
Class.
Phone number
JF underscore underscore double underscore.
It double underscore parentheses serve and the on then self but num equal num.
We want to use the first class and the second class embattled line.
We can do that without inheritance so we will use inheritance and avoid reputation and code inheritance.
It's easy to understand.
You could think about it as a preventive for reputation and good so class for num when inherit data
from user data when inherit missiles from plus user data so class phone num user data.
Jeff and it self and the NUM we will add data to barometer name and age.
Side num then we will add this line of code Super which is user data not normal underscored in it double
underscore
name and age.
We will assign our users to the second class which inherit missiles of the fittest plus user data user
underscored one equal
phone
num
Sara
forty one two three four five six seven eight nine.
So as a class phone number.
Name and age.
From the first class user data.
Suppose we want to inherit from user data and modifies that inheritance user.
Suppose we have user to equal.
David and 50
wont update that user.
We will use overriding perverted user to
equal for no
David.
Sexy
2 3 4 5 6 7 collect shift and enter.
This will change the age of their user to
that it's we will get 60.
So this is called overriding that's all world class or the parent place.
User 1 we will use 4 numbers class to update their user name.
There is a name and age that understood one.
Equal
Sara
and 13
user underscore one equal phone number
zone
and nine eight seven six five four three two one.
For example shift and enter user 1.
Equal user 1 not name will get John.
So we update the user 1 a name and age and phone number.
Let's try to extract User 1 that each will get 15 also for user 1
not for numbers.
We will get the phone number nine eight seven six five four three two one.
Thank you for watching.
See you next lecture.