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 *

Already have an account? Sign In »

4 hours 19 minutes
Video Transcription
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.
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.
Now let's begin. So what is polymorphism
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.
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.
So there are two types of polymorphism. The first type is static polymorphism
and in static appointment, pulling more fizz. Um, what happens is
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.
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.
And once again,
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.
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.
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
or the first line over here that explains this principle of ah,
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.
But give your own implementation of it
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.
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
start to see how polymorphism
uh uh comes into this picture.
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