Hello, in this video, I am going to show you function overriding. So function overriding is when we have a class that extends, you know, another class, and the parent class has a function, let's say open door. And we, you know, let's say we want all the other functionality of that class, but that one particular function, we want it to be slightly different, but we want the same name. And that's what override it. So we override that functionality. And we have the print on info as well.
So for the understand demonstrating on the open door to override the functionality, as you can see, when I run it to open door, and I'm gonna say doors opening, that's where I want to be in the beauty say, all you have to do is literally just put the function in that same fashion, you know, this right here and now if I was to echo and say, door opening. Now far below that, as you can say, says door is opening, even though it's still calling the constructor and destructor from this class, and this ultimately the vehicle class, which the car class is inheriting from, but because what it does, same with the constructor and the destructor, it looks in the child class first to the class that you create an object, if it exists there, it will use that particular one. If it does that, it will go to the parent and look the exists there.
If not, you'll go to the you know, the parents parent, if that, you know inherit from another class. And until it finds it unless you you know, try to call a function that doesn't exist, then he'll give you an error. So that is function overriding nothing more to it than that. You can override it, you know override functions that return value. Maybe in this case, this one doesn't return a value, and you want this one to return a value that's possible. As an extra task, I want you to implement that as another extra task.
I want you to implement a function, let's say in this class that takes in some values, then implemented here in the same fashion that takes in the same amount of value, but it does something different with it. One might echo out, you know, two numbers added together. The other one might just return that result here. So you could store in a variable and use it later on. But yeah, that is function overriding simple stuff, but really useful. If you have any questions, feel free to pop me a message.
And as usual, I look forward to seeing you in the next video.