9.1 Intro to Polymorphism
Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or
Already have an account? Sign In »

Video Transcription
00:00
hi and welcome back to the course. I hope you guys are doing well. And if you remember in the last model we discussed the idea of inheritance and the old P component of inheritance. And in this module, we're going to be discussing the very last component of O. P called polymorphism.
00:17
Now is always I've listed out some learning objectives for us to follow. The first point that we're gonna be going over is the general and basic slash high level idea of understanding polymorphism and what it entails. Then we'll move on to discussing the use cases of polymorphism as well as why you would want to use that.
00:37
Now let's begin. So what is polymorphism
00:41
if we start with the formal definition? Polymorphism refers to a principal in biology. So not even in programming to begin with in which an organism or species can have many different forms or stages. This very principle can also be applied to object or into programming or old P, and that includes languages such as Java.
01:00
Now the basic idea is that sub classes of eight class of their parent class can define their own unique behaviors and yet shares some of the same functionality of the parent class, and that is essentially what polymorphism is all about. End, uh, promotes.
01:15
So there are two types of polymorphism. The first type is static polymorphism
01:21
and in static appointment, pulling more fizz. Um, what happens is
01:26
let's say there is a specific method called that your program is making and you have multiple methods with the same name, but with different parameters.
01:36
When that method is invoked, the way the program would decide, uh, or when the program would decide which method to invoke is done during compile time and that is called compile time polymorphism, or static polymorphism, and that is achieved through method overloading.
01:55
And once again,
01:56
uh, the way Java knows which method to pick is done through the method signature of of your methods that you've created and which method on the method that is being called said matches the method signature to the method that is being called.
02:12
And then secondly, we have dynamic polymorphism, and that is a process in which a call to an overdone method is resolved at runtime. Therefore, it is also referred to as a runtime polymorphism and this dynamic polymorphism is achieved through method overriding.
02:31
All right, so to summarize things in this video lecture we discuss what polymorphism is and the use of polymorphism. Now, I'd like to elaborate on in a second bullet point here if we go back to our previous slide, this very last line over here
02:47
or the first line over here that explains this principle of ah,
02:52
polymorphism and biology. The ability of it to take on different forms is one of its main use cases. And that is why we would want to use it in our program, something like method overloading and gives you the ability to take a method that or take a method name that has already been defined and created and use the same thing.
03:12
But give your own implementation of it
03:14
and method overriding does the same. It takes a method that is already defined and she waited in your parent class. But you're able to inherit that method and you're able to override that method with your own implementation.
03:28
Okay, so for now, this is all that we have on polymorphism. But what we will be doing is in the next video coming up, we will be reviewing one of the labs we did. And this is the math lab that we did, if you remember. And this lab was done in module four. And here we will
03:47
start to see how polymorphism
03:50
uh uh comes into this picture.
03:53
And I hope you guys enjoyed this video lecture. And if you have any questions at all, feel free to connect with me via Ellington. And I would be more than happy to answer any of your questions. Thank you very much for watching. And I look forward to seeing you in the lab review coming up next.
Up Next
Similar Content