Hello, in this Java video we are going to cover method overloading. So method overloading is when you have two or more methods have the exact same name, but they have a different you know, even number of parameters or different type of parameters they accept now that the compiler knows which method to you know, use when you actually call a method. So, let me use an example, probably Pablo I call it Hello. In this simple system, I'm gonna walk the function the return type that doesn't matter doesn't have to be static. If you know you're doing something a bit more complex, only slightly different if you know about that. I find well Okay, we're printing x.
And if we just call it Hello, passing seven, so it should print out. So that's pretty cool. What will happen if I duplicate the method? I'm fine with it. It gives an error. The error is duplicate method.
So we can even rename it and you know, rename the method, but that's not method overloading. So it doesn't know which one to calls because imagine if I said, you know, x times two, which one should be calling at this point, when I've caught it, it does not know. We can do some distinctions and method overloading. If for example, I added another variable into why no arrows now. And if I do y, for run, it will still get seven. Whereas if I were to call Hello now and do this a full color seven We'll get a value 28 because it knows, to cool this method.
We can go step further. So for copy that, and I say if I have no parameters whatsoever, and I just do a system out world, five, one that nothing should change in the console. I forgot public, public, nothing should change the content you didn't. And I thought I can Hello, again, but without the parameters, it will run hello world and they don't have to be in the exact order that the methods are written don't have to keep calling them. And another thing you know, the beauty of methods function, whatever you want to call them, you can just keep calling them again and again. And that's not just you need to method overloaded, as does four types of methods.
I think the printer hello world and I want to show you one more example. Before I get this, I've got this one. So, if I say I wanted one parameter on two different dates, we can do that. If I do x gives no error. And if instead I want to do any statements or x equals true, then I want to print something out. through it.
Again, this should not change it does not if I do Hello my claim true inside of it. It prints that it is true. If I were to duplicate this long and false, it will also say, it is false that in method overloading it is when you have two or more methods with the exact same name, but the actual number of parameters changes, and all the data types of those parameters change and the actual functionality within each method river is similar or it could be totally different. That is up to you. Thanks for watching. If you have any questions, feel free to reach out.
There'll be a link to the GitHub page, which contains all the source code from literally every part in this series. And I look forward to seeing you in the next awesome Java video.