Hey, welcome back.
In the previous video, you learned that you could create a class which would inherit the methods of
another class.
For example, our secure credit card class was able to inherit the validate method class.
In other words, when we create an instance using secure credit cards, that instance has access to
the validate methods which was defined in the credit card class.
So this method was called in here.
Now, sometimes that method that you are inheriting might not be enough.
You might want to change something from that method.
In that case, what you want to do in the child class is you want to override that method.
So let's take an example.
In the Python console.
I will not be modifying the code for this.
I just want to show you the concept in this video, the concept behind overwriting a method.
So let's take a ticket class, right?
It has an init method.
Let's just pass here to keep it simple.
And then this ticket method has this generate method, right?
Which returns.
Something like, Hello, this is your ticket.
So I'm not including any parameters here.
I just want to make a point about inheritance.
So that is the ticket class right now.
If you want to create a class which inherits from that class, let's say digital.
Ticket.
So we would supply tickets here.
And then perhaps you want to add more methods such as define download.
They can download the tickets.
You have some codes here and so on.
And then perhaps you might want to override that method because you might want to return something else
instead of that strings.
Right.
In that case, all you have to do is define the method again.
So the method name should be exactly the same as in the parent class.
Generate.
And then returns something else like, Hi, this is your ticket.
So now this string is different from that, right?
So let's execute this class.
Let's instantiate digital ticket.
It doesn't take any arguments, right?
Because the init method doesn't take any other parameters other than self.
So that is the method.
Now generate will of course.
Output.
Hi.
This is your ticket.
So it outputs this string instead of that.
So you can override a method of the parent class by defining that method in the child's class.
Of course, if we say TW is equal to tickets, which is the parent class to generate, of course it
returns.
Hello, this is your ticket.
So that is a string of the ticket class because when you inherit from a class, you do not modify the
parent class, you only modify the child class.
And that's the concept I wanted to talk about in this video.
So thanks a lot and see you in the next one.