4.6 Method Overloading
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 our previous lecture, we did a lab in which we implemented the idea or concept of method overriding by creating a parent and child class as well as a sort of tester to see how both classes work and how this concept of method overriding works.
00:20
And in this video lecture,
00:22
we're going to be going over the concept of method overloading. Now, before I start in the last videos and slide,
00:32
it said method Sorry, Module five, method over loading. That should be just method overloading were still in module, for that was a error and it husband fixed. It was just mentioning that to make sure that you don't get confused and we're still in model for So that was just a small mistake that I fixed
00:52
and
00:53
moving on. We have a few learning objectives that I'd like you to keep in mind when we go go throughout the video,
01:00
The first point that we're gonna be
01:03
covering is the general high level idea of what method overloading is.
01:07
Then gradually, we're gonna move on to understanding why we would ever have the need off overloading any method or using this idea of method overloading.
01:18
Finally, I'm gonna talk about some differences between method overloading and overriding, because that seems to be a point of confusion for a lot of people, including programmers.
01:30
So what is method overloading to begin
01:33
now? If we start with the formal definition method, overloading gives you the ability to give a method or several methods the same name as a pre existing one, but with a different method. Signature.
01:46
Now if we talk about method signatures, a method signature in Java consists of the following items, a name
01:55
and the number type as well as order of its parameters.
02:00
No, I'd like to discuss some advantages of method overloading.
02:04
The first advantage that it ah comes along with is three idea to call a similar method for different types of data. Since each method can have a different return type
02:17
and then it encourages cleanliness of code
02:21
as well as readability of code.
02:24
Now, why would we ever want to use method overloading?
02:29
So the first point over here really sums that questions answer up. Let's say we have a class in which we are doing some sort of mathematical calculations and we have a funk, a method or function called,
02:42
Um, calculate. Now let's say that calculate method, um, adds two integers together.
02:50
And what if we want to use the same name of that method but add two decimals together or subtract to introduce together? It would perfectly make sense to use the same name calculate. But then we would have to change the signature of our method if we want to use the same name.
03:09
Now moving on, we're gonna be discussing some differences between method overriding and method overloading. So
03:16
here are some key differences. First method overloading increases readability. Overall, it ah is done within the class on Lee. So nothing external
03:29
and then the parameters of each method that you're overloading must be different.
03:34
And finally, changing the return type of a method doesn't count as overloading that method.
03:39
If we move on to the method overriding side, it is used mainly to provide a specific sort of implementation of a certain method,
03:50
and it occurs in two classes that have something called a is a relationship.
03:55
The parameters must be exactly the same,
03:59
and the return type of the method that you are overriding must be the same. Or this ordinary must be a subclass of the type returned by the method in the parent class.
04:12
All right, so two summer up, USAA To sum up this video lecture,
04:17
we went over the concept of method overloading
04:21
and the need of method overloading. Why would ever find ourselves overloading a method? And that was exclaimed through the math calculate method example.
04:32
And finally, the difference is a few key differences between method overloading and method overriding.
04:40
Now, in the next video, we're gonna be doing our second lab of this module, which is called math overload. And as you can tell by the name, we're gonna be doing some method overloading, and we will actually see how this concept is implemented in a real world program.
04:57
Now, as always, if you have any questions at all, feel free to contact me. The Ellington and I would be more than happy to any to answer any of your questions. Thank you very much for watching. And I look forward to seeing you in the lab
Up Next
Similar Content