00:01
Hello student here, what do you understand by the polymorphism? so polymorphism is the ability of a programming language to allow objects of different types to respond to the same message.
00:13
So this is achieved by allowing objects to overwrite the method defined by their parent class.
00:20
Polymorphism is a powerful feature that allows us to write more flexible and reusable code.
00:27
So for example, we can use polymorphism to create abstract classes and interfaces that define the common behavior of different types of objects.
00:36
We can then create concrete subclasses that implement the specific behavior.
00:43
Polymorphism is also useful for writing the generic code, which is the code that can be used to operate on different types of data.
00:50
For example, we can write a generic sorting algorithm that can be used to sort a list of any type of objects.
00:56
So here we can use the sort for number and as well as we can use sort for character, even for string also.
01:11
So we can apply anywhere.
01:14
So this can be achieved only with the help of a polymorphism.
01:18
Now the type of the polymorphism, ad -hoc polymorphism, parametric polymorphism and a subtype polymorphism ad -hoc.
01:26
So, this is the simplest type of the polymorphism.
01:29
It occurs when a function can be called with different type of the argument.
01:34
For example, the print function in the java can be called with the argument of any type such as string, such as number, such as object.
01:42
So this is ad -hoc.
01:43
Number two is a parametric.
01:45
The type of polymorphism allow us to write the generic code that can be used to operate on different type of data.
01:52
For example, the list class in java is a generic class and can be used to store a list of any type of the object.
02:00
So that is parametric.
02:01
Here we are using parameters with the object.
02:04
Subtype polymorphism, this type of the polymorphism allow us to override method defined by the parent class.
02:11
For example, draw method is defined by the shape class in java.
02:16
Subclasses of the shape class such as circle and square class can override the draw method to implement their own specific drawing behavior.
02:26
Here the example of polymorphism.
02:28
Here i have taken one example.
02:30
Here i have taken the class animals.
02:32
Here i have defined the function speak and i am not writing anything.
02:38
That's why i have written class dog, animal type...