4.4 Method Overriding

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 »

Time
4 hours 19 minutes
Difficulty
Beginner
CEU/CPE
4
Video Transcription
00:01
hi and welcome back to the course. I hope you guys are doing well. And in this video lecture, we're gonna be discussing and going over The idea of method overriding
00:12
now is always. I've listed out some learning objectives for you to follow.
00:16
And the first point that we're gonna be discussing is the basic and high level idea or details of method overriding as well as what it entails.
00:27
Then we're gonna be moving on to discussing why would ever have the need of overriding a method and how we can see ourselves actually doing that in a real life computer program.
00:39
So what is method overriding to begin
00:43
now, if we start with the formal definition method, overriding allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super classes or parent classes.
00:58
When a method in a subclass has the same name
01:02
parameters or signature and return type as a method in Supercross, then the method in the sub class is set to override the method in the super class.
01:14
No,
01:15
the reason for why I would ever use method overriding is that let's say you have a method and let's call it a run or print, or calculate whatever it may be. Let's see you have that method in your parent class,
01:29
but you want to give it a specific implementation in your sub class and old. And in order to do that, that's where you would override the method. But you would still have the same name, same parameters, same signature on dhe. The return type and a signature
01:47
is consists of parameters, name
01:51
and ah, the types of your parameters.
01:55
Now there are some advantages of method overriding that I'd like to discuss. So as I mentioned a few seconds ago, it allows for a different implementation off the method with the same name in the parent class.
02:06
And one more thing that we can do it with a method of writing is that it gives us the ability to invoke the method that was originally created in the parent class by using the super keyword in the sub class so you can call that method in your parent class.
02:24
Let's say that method is called
02:27
run or print in yourself class by using the super cured.
02:32
No,
02:34
Once we get into our lab. Following this video, you will better understand this concept and see how it actually works.
02:43
So to quickly summarize what we went over and this video lecture, we discussed the high level idea of method overriding as well as the need of method of writing and why we would ever do that.
02:54
As I mentioned in the lab coming up, we will be creating a parent and a child class, and we will see how method overriding actually works.
03:07
And as always, if you have any questions at all, feel free to contact me, be elected, 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.
Up Next