Come back to the next tutorial. In this one, I'm going to continue talking about method overloading. A couple of more things that I want to discuss, it's gonna be really short one, purely the things that would be really helpful for you to understand the concept of or living in a little bit more detail. So let's get started. And I have a class prototype sort of thing for you. So these are the three things that we already talked about, right?
And this is a new class. So what I have right now is, let me delete this one. What I have right now is God's will only questions new file, create a new class, and I have created one method. And there is a variable string variable one and variable two. And it prints something that I'm the first one, right. So let's copy this, I want to just go over a couple of cases.
Fairly simple, small, but really helpful to understand the concept. So let's say if I give a different name, call maybe variable, three and variable For everything, it's gonna be fine. No, that's what I want to show you. So this is gonna be a compile time error. Because the argument list is exactly the same. It doesn't matter what name we use.
It's the type. So the both have two arguments of type, string and int. So that's why the argument list is exactly the same. And it's gonna be a compile timer. It's gonna say the same thing that the web ID method, the method name exists in the class, right? If I change the type, let's say I change this one to a string.
This one is going to explain now, doesn't matter if I have the same name for the variables or not, but I have different types. The first one is the same, but the list does not match the same. The second one in the first method is in and in this one, it's strange, so this one is fine. So let's name it the second overload. So we need to keep that thing in mind that important part is to change the type, not the main The arguments. So this is the second case, though, one more case that I want to cover is, as I mentioned is gonna be really small.
But it's very important that this comes in a lot of interviews as well discussion that can be overload based on the return type. All right, so right now you guys can see this is wide, wide return type, if I say it in, right, public static and, and have to return something that returns zero, return zero. So it's fine, right? So both the return types are different. It's fine. We can overload this we can this is perfectly fine because we have the return type is different, but the method name and argument list are also different.
But what if I, can I overload just on return type, then it's a big No. So I'll add this as a rule cannot overload just on return type. So it does not matter matter, it will throw a comm violation error, more than one method with the same name and argument list, it cannot be same in a given class. Even though they have a different type, it doesn't matter. And method return type does not even matter in case of overloading. So if I do this, let's say I have a different return type, and I use the same type, let's say I gave it in, it started giving me errors, right?
It started throwing all these errors that duplicate method name, even though we have one as wide and one as in it doesn't matter. So even if we do that, it's okay. It doesn't matter. So the important thing to keep in mind is we have to keep these things different. So what we can do is we can put it straying lower double anything, but because we are again putting it Boyd we have to delete the return because in void we are not returning anything. Yeah, but the important part is We cannot overload just on it on time.
So that's about it guys. So that's what I wanted to cover in this tutorial. files will be there on the web so you guys can download it easily and follow them whenever you want. And stay tuned for the next lectures guys. Thanks for learning this one.