WEBVTT

00:00.000 --> 00:03.000
Inheritance and method overriding.

00:03.000 --> 00:06.000
In this video, we will understand

00:06.000 --> 00:09.000
the concept of inheritance in Python programming.

00:09.000 --> 00:13.000
Apply method overriding to customized class behavior.

00:13.000 --> 00:17.000
Use the super function to extend parent class functionality.

00:17.000 --> 00:20.000
Welcome to the world of Python programming.

00:20.000 --> 00:22.000
Imagine you're building a game.

00:22.000 --> 00:25.000
You start with a general class called Animal.

00:25.000 --> 00:29.000
Now, what if you want to create more specific animals like dog and animal?

00:29.000 --> 00:35.000
Instead of starting from scratch, you can use inheritance.

00:35.000 --> 00:38.000
Understanding inheritance.

00:38.000 --> 00:42.000
Inheritance lets us create new classes called subclasses.

00:42.000 --> 00:47.000
That take properties and methods from existing classes called superclasses.

00:47.000 --> 00:53.000
So, dog and cat can inherit everything from animal like how they eat or move.

00:53.000 --> 00:56.000
Method overriding and super function.

00:56.000 --> 00:59.000
Let us learn how to do that in Python.

00:59.000 --> 01:02.000
We start by creating subclasses using the correct syntax.

01:02.000 --> 01:07.000
Then, we can override methods to give each animal its own unique behavior.

01:07.000 --> 01:12.000
In method overriding, you redefine a method in the subclass to give it a new meaning.

01:12.000 --> 01:16.000
Like a cat saying, meow, and a dog saying, woof!

01:16.000 --> 01:20.000
And here's a super trick. Use the super function.

01:20.000 --> 01:24.000
It helps you access the parent class's methods and attributes.

01:24.000 --> 01:28.000
So, you don't lose anything useful from the original class.

01:28.000 --> 01:31.000
Step up to the challenge.

01:31.000 --> 01:34.000
Try creating a class hierarchy.

01:34.000 --> 01:39.000
Add unique behaviors and override methods to see the magic of inheritance in action.

01:39.000 --> 01:43.000
We start with a class animal that has a name and a speak method.

01:43.000 --> 01:47.000
Then, we create dog and cat classes that inherit from animal.

01:47.000 --> 01:51.000
They override the speak method to say, woof and meow.

01:51.000 --> 01:56.000
We use super function to reuse the parent class's information and add more detail.

01:56.000 --> 02:03.000
Finally, we create dog and cat objects to see inheritance and method overriding in action.

02:03.000 --> 02:06.000
Let's code the future. One class at a time.

