1
00:00:01,359 --> 00:00:02,260
Hey, welcome back.

2
00:00:02,290 --> 00:00:10,990
In the previous video, you learned that you could create a class which would inherit the methods of

3
00:00:10,990 --> 00:00:12,280
another class.

4
00:00:13,330 --> 00:00:20,060
For example, our secure credit card class was able to inherit the validate method class.

5
00:00:20,080 --> 00:00:29,530
In other words, when we create an instance using secure credit cards, that instance has access to

6
00:00:29,530 --> 00:00:35,050
the validate methods which was defined in the credit card class.

7
00:00:36,120 --> 00:00:39,720
So this method was called in here.

8
00:00:40,290 --> 00:00:46,850
Now, sometimes that method that you are inheriting might not be enough.

9
00:00:46,860 --> 00:00:49,950
You might want to change something from that method.

10
00:00:50,310 --> 00:00:56,220
In that case, what you want to do in the child class is you want to override that method.

11
00:00:56,250 --> 00:00:57,990
So let's take an example.

12
00:00:57,990 --> 00:00:59,280
In the Python console.

13
00:00:59,280 --> 00:01:01,500
I will not be modifying the code for this.

14
00:01:01,500 --> 00:01:07,500
I just want to show you the concept in this video, the concept behind overwriting a method.

15
00:01:08,130 --> 00:01:11,490
So let's take a ticket class, right?

16
00:01:12,330 --> 00:01:15,090
It has an init method.

17
00:01:16,180 --> 00:01:18,910
Let's just pass here to keep it simple.

18
00:01:18,910 --> 00:01:22,570
And then this ticket method has this generate method, right?

19
00:01:23,080 --> 00:01:25,030
Which returns.

20
00:01:26,300 --> 00:01:31,100
Something like, Hello, this is your ticket.

21
00:01:31,100 --> 00:01:34,850
So I'm not including any parameters here.

22
00:01:35,300 --> 00:01:39,140
I just want to make a point about inheritance.

23
00:01:39,140 --> 00:01:41,900
So that is the ticket class right now.

24
00:01:42,110 --> 00:01:47,450
If you want to create a class which inherits from that class, let's say digital.

25
00:01:48,990 --> 00:01:49,800
Ticket.

26
00:01:50,670 --> 00:01:53,520
So we would supply tickets here.

27
00:01:54,840 --> 00:02:01,530
And then perhaps you want to add more methods such as define download.

28
00:02:01,830 --> 00:02:03,630
They can download the tickets.

29
00:02:03,660 --> 00:02:06,060
You have some codes here and so on.

30
00:02:06,180 --> 00:02:15,720
And then perhaps you might want to override that method because you might want to return something else

31
00:02:15,720 --> 00:02:17,340
instead of that strings.

32
00:02:17,340 --> 00:02:18,060
Right.

33
00:02:18,090 --> 00:02:23,660
In that case, all you have to do is define the method again.

34
00:02:23,670 --> 00:02:28,440
So the method name should be exactly the same as in the parent class.

35
00:02:28,920 --> 00:02:30,030
Generate.

36
00:02:31,110 --> 00:02:36,670
And then returns something else like, Hi, this is your ticket.

37
00:02:36,690 --> 00:02:39,740
So now this string is different from that, right?

38
00:02:39,750 --> 00:02:41,490
So let's execute this class.

39
00:02:41,940 --> 00:02:46,470
Let's instantiate digital ticket.

40
00:02:46,590 --> 00:02:49,560
It doesn't take any arguments, right?

41
00:02:49,560 --> 00:02:55,250
Because the init method doesn't take any other parameters other than self.

42
00:02:55,260 --> 00:02:56,760
So that is the method.

43
00:02:56,790 --> 00:03:00,900
Now generate will of course.

44
00:03:03,420 --> 00:03:04,310
Output.

45
00:03:04,320 --> 00:03:04,920
Hi.

46
00:03:04,920 --> 00:03:06,180
This is your ticket.

47
00:03:07,170 --> 00:03:10,560
So it outputs this string instead of that.

48
00:03:11,070 --> 00:03:19,770
So you can override a method of the parent class by defining that method in the child's class.

49
00:03:20,310 --> 00:03:30,150
Of course, if we say TW is equal to tickets, which is the parent class to generate, of course it

50
00:03:30,150 --> 00:03:30,870
returns.

51
00:03:30,870 --> 00:03:32,670
Hello, this is your ticket.

52
00:03:32,820 --> 00:03:40,650
So that is a string of the ticket class because when you inherit from a class, you do not modify the

53
00:03:40,650 --> 00:03:44,520
parent class, you only modify the child class.

54
00:03:44,820 --> 00:03:48,080
And that's the concept I wanted to talk about in this video.

55
00:03:48,090 --> 00:03:50,160
So thanks a lot and see you in the next one.

