Method overloading is a Java concept where multiple methods in the same class share the same name but have different signatures, defined by the number of parameters, their data types, and their sequence. This achieves compile-time polymorphism, allowing the same behavior to be performed through different input combinations. The return type and access modifiers are not considered in method signatures. For example, a login method can accept different parameter combinations (username/password, mobile number/OTP) while maintaining the same method name, demonstrating how method overloading enables flexible and reusable code.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Java Method Overloading Class by Shishita Bhat SirAdded:
Okay. So guys um listen now everyone close the book just observe here there is a concept called signature what is this signature what is the signature not this signature not this signature I think her brand that she is able to recall okay so listen first I'll give Here's the definition of signature.
Probably you will not understand.
Signature is something which is used to describe the parameters of a constructor or a method. Rather than the definition, I'll try to give you an example. You'll understand it. Okay.
Now I'm going to create a class called as let's say calculator.
In this class I write a method. Okay, I read a method called void add the numbers. Okay, I read a method to add the numbers.
Now let's say I want to add three numbers. one is integer I the first number and then double D the second number and then again let's say uh long long the third number how many numbers I would like to add >> three numbers so basically it is a way to describe this particular parameters now for example if someone ask you describe the signature of the add method Listen to me. Describe the signature of the air method. So you have to describe in this way. First of all, whenever you are describing the signature, you have to go in the priority. The first priority is always given to the number of parameters.
The number of parameters in our case if someone askked you to describe the signature of the add method totally how many parameters are there in our example three parameters are there [snorts] clear? Similarly the second priority is always given to is always given to the type of parameter.
The type of parameters.
Okay. Now if someone ask you what is the type of the parameter you can say one is integer one is double and another one is long. So I have long as one parameter int is the data type of one parameter another one double as the data type of another parameter or in another way let's say there is a method which is taking two integer parameter one float as the parameter. So you can say two integer and one float.
So we are describing the data type. Type means data type of the parameter. The third priority is always given to the sequence or the order of parameter. What is that? Sequence or the order of parameter. So now in our case tell me how many parameters are there?
>> Three. the first one, the second one and then the third one. Correct? So here we are not interested in the name of the parameter. Instead of IDL, I can take it as LM, right? A1, A2, A3. Name of the parameter can be anything. So we are focusing more on the data type. What is the first?
>> Integer. Second one.
>> Double. Observe the sequence. Second one is double. The third one is >> law.
>> Law.
These three criterias which are used to describe the parameter is technically called as what? Signature.
[clears throat] So signature is the one which is used to describe the parameters of a method or a constructor because the parameters are applicable not only for a constructor, it is even applicable for a method. Are we clear? Now you're right. Let's say for example I'm going to take you through another example. Let's say I have a method called a calculator which is going to calculate something.
Calculate it's going to calculate something. Okay. Let's say I need one integer first number integer second number and um and let's say a float float number.
So if someone ask you describe the signature of the calculate method, how would you describe?
You should say how many number of parameter >> three parameters. Okay. Out of that two are integer. One is flow. But what is the order or the sequence? First is integer, second is flow, third is integer. That is a that is the signature. Hope everyone understood what is the meaning of a signature. Right?
Take some points.
Signature.
Signature.
Signature is the one. Signature is the one which is used to describe the parameters.
[clears throat] Signature is the one which is used to describe the parameters.
Signature is the one which is used to describe the parameters.
Next, there are three criterias.
There are three criterias which defines a signature. There are three criterias which defines the signature.
There are three criteria which defines the signature.
What is the first one? All of that and the order should be in the same way guys. The priority should always be given in this way. Okay, what's the first one? The number of parameters.
Write it down. The first one is the number of parameters.
The second one is the type of parameters and the third one is the sequence or order of parameters.
Let's say I have only one parameter.
Then do you think the sequence or order does it really matter?
>> It's like you are the only one person in the running race. No, you are the first, you are the last. There was an ad. No some ad he says come and says that dad I got the first place first or second oh second place in the running list first place he says how many are there first congratulate and then he says that how many were there is it only one okay so when you have only one parameter the order does not matter because that itself is the first that itself is the second Okay. So while you are defining the signature or describing the signature or describing the parameter, you always have to go in this priority all of a sudden. Why are we talking about this?
This is really important for today's topic here.
Deal done. Okay. Close book.
Hello. I'll come back to this [clears throat] close book.
We're talking about totally a new concept. Okay, totally a new concept.
Everyone understood signature.
>> Just keep it aside for a time being.
Keep it aside. We'll come back to that topic again. Now, what's the meaning of a method? Method means a behavior.
Behavior means some work, some task, some job. Yeah. Sometimes certain activity or certain job or certain task can be done in different possible ways.
Hi focus here. You're dreaming of something. Uh now for example you have a mobile phone and you want to unlock the mobile. Okay.
If you want to unlock the mobile, can I say unlocking the mobile is a behavior?
>> I want to unlock the mobile. That's the behavior. If you really want to unlock the mobile, what are the different ways to unlock the mobile? First is let's say the first is the face ID.
Face ID or the retina, right? Using that I can unlock the mobile. That's the first one. The second one, let's say weekend. Okay. You are at your PG or at your home. You have a plate full of facials.
Your phone is not recognizing you.
Are you clear? Now I want to unlock. How to unlock?
>> You can use the huh um the thumb the finger impression thumb impression that's another way of unlocking the mobile. Let's say you are cooking something. Okay. Your your hands are too much oily. You will be you will not be able to use that. Are you clear now? So you can use there are different ways to unlock. One is facial recognition and unlock. Another one is the pin. You can enter the pin or the pattern and unlock. Another one is by using the uh the thumb impression. Okay.
Can I say unlock is one behavior and I'm unlocking this mobile by different possible ways. Clear? Everybody understand? So remember any any particular job or the workload or some task can be performed in different possible ways depending on the situation to situation. Is this clear now? Okay.
So it means to say there is a method.
Method means some work. Okay, this method, this method or this job can be executed in different possible ways. In different possible ways, in a first way, in a second way, in a third way.
This is technically called as polymorphism. What we call polymorphism.
Polymorphism means polymorphism. It is derived from some language. There's a word I don't know Latin or Gino or something. Poly means >> many. Poly means >> many. Morphe means farms.
Morphe means forms.
Getting any work done, any one single work done in different possible ways.
Getting any single work done in multiple different forms is called as what?
Polymorphism.
clear. I'll just give you another example. Let's say there is a website and you want to you know any banking website or anything that you want to login. Can I say login is a behavior? Login is the behavior. So if you want to login there are two ways to login. The first one you enter the username and the password and you can login. That's a one way of logging in.
In fact, this option is there even in uh uh ICICI banking. Okay, I can enter the username and the password. I can login.
If you can't tell me your username, password, I can demonstrate practically.
Okay, that's a one way of logging in.
Sometimes people like me, I have the tendency to forget my password. I honestly I don't remember the passwords.
Okay. So in my case, what do I do is I can log into the same banking application by entering my mobile number, registered mobile number, register mobile number. I can enter my registered mobile number so that I'm going to get an OTP and I enter the OTP and login, right? What am I doing ultimately? I'm logging in. But different forms of login. Sometimes I enter username and the password and login. Sometimes I'm going to enter my registered mobile number along with the OTP and log in but ultimately I'm logging in different forms of doing the same activity that different forms of doing the same activity is called as what polymorphism are you clear so now how do we achieve this in Java I want to perform certain task in different possible ways so for that for that okay we can achieve this concept called polymorphism by using a Java concept called method overloading. What is that?
>> Method overloading.
Then what is the difference between method overloading and polymorphism?
Method overloading is a way to achieve polymorphism. So polymorphism is a result and the way to achieve that result is called as what? Method overloading. Now I need energy.
Ultimately I need energy. For that I'm going to take some food and someone ask you what is the difference between food and the energy.
Are you clear now? Yeah. I when I have the food I'm going to get the energy. So when you use the concept called method overloading you are going to achieve polymorphism. So polymorphism is the result and to achieve that we use something called method overloading. So the topic of the day is polymorphism and method overloading. Again to be precise in polymorphism there are two types of polymorphism. One is called compile time polymorphism and the other one is called runtime polymorphism. But in today's class we're going to talk only about a compile time polymorphism. That is we are going to achieve that by using method over loading. That's the topic.
So to understand the method overloading we need to know something called signature.
Clear? So coming back to the signature concept. Okay. In the signature we are not going to consider the return type of the method. It does not matter only the parameter. We're going to consider only the parameter. We don't consider the return type of the method. Are you clear? Good. So now just observe guys.
now as the same example.
So I want to log to the website.
Login is my behavior. Okay. Sometimes I can login. Are you able to see this better? Okay. If you want to log in in some time z username username and I'm going to use the the password going to use the password same login I can login in another way. What is that?
by using the registered mobile number.
By using the registered mobile number as well as when I enter the mobile number, I'm going to get an OTP. So, I'm going to enter the OTP.
Now, tell me if you consider this or correlate this with Java.
What is the data type of username and the password?
Huh? String and string. username is string and then the password is >> string password is string or else I can log to the the the website by using mobile number what is the data type of mobile number >> long because it's a 10digit number of course not the uh double and uh the float because your mobile number is not a decimal value no 880570822 Right? What EP?
>> A fourdigit or a six-digit number, >> it is an integer.
So observe this. In my case, I have to write two methods. I write two methods.
And the first method which takes string and string as the parameter nothing but username, password. The same another method with the same name where it is going to take long mobile number and integer OTP as the parameter. Let's see how to achieve this practically. Okay, focus here please.
I create a class called as website.
This is my class. I have to write a method called login. What is the method name? Login.
How many login methods I should write?
>> One two now. Two methods. Observe here the method names must be same. Why method names must be same sir? It is giving an error. If I write two multip multiple methods with the same name obviously compilation error. So that method duplication.
Are you going to understand? So hence we have to change this. What has to be changed? The signature. The signature has to be changed in the first one username and the other one is >> the password. Here it is long mobile number and the other one is integer OTP.
Now observe have a look into this. Have a look into this. Okay.
In the class same class I'm having more than one method.
I'm having more than one method. Okay.
What is same? What is difference here?
Method names are same. Okay.
>> Yeah. Don't call it as parameter.
Signatures are different. What do you mean by signature? Now, can you tell me signature is always evaluated based on the order. What is the first one? Number of parameters. Here number of parameters. How many parameters?
In this case two parameters so same are duplication.
Now when the number of parameters are same it tries to evaluate the second one. What's the second one? Five. Here it is string and string. Whereas in this case it is long and integer. Can I say there is a change in the parameter?
Let's assume that is also string and string. String and string. Then it in that case sequence also does not matter.
It becomes compilation error.
Okay. When you have more than one method, very important with the same name. What is motivating us to keep the same name?
Why are we keeping the same name? You could have given the different different names. No, >> why are we giving the same name? Because it is representing the same activity, same behavior. That's where it is that's the reason we're keeping the same name.
If it is one is login, another one is log out, probably I would have given the different name. I'm keeping the same name because my behavior is same. My activity is same. That's the reason we are keeping the same method name. But when you have more than one method with the same name, it leads to compilation error saying that method duplication. To avoid that, what do we do? We keep the different signature.
The simple concept is called as what?
Method overloading.
So what is the definition of method overloading? And method overloading is nothing but having multiple methods in the same class not in two separate classes. Let's say I have a class called the bird class has a method called eat because the bird eat another class called tiger. Tiger also eats. Now why?
No because this is separate class. This is separate class. So having more than one methods in a class with the same name but change in the signature change in the method signature is called as method overloading.
Change in the signature means either there has to be change in the number of parameters. No no sir number of parameters same in that case at least there has to be change in the type or the data type of the parameter. No sir data type is also same sir at least there has to be change in the sequence or the order of parameters is this clear now that's called method overloading in method overloading what we consider is guys that's very very important in method overloading we consider only method name and the signature that is right side to this is what considered okay mhm Okay.
Now observe in this case we only consider this from here we are going to consider only right side thing. What is that? We are going to consider the name of the method. We have to consider the name of the method and the signature. The left side method return type we don't consider we don't consider the method return type whether written types are same or not does not matter if it is same also we don't consider if it is different also we don't consider we only consider the method name and the signature that is nothing but the parameters is this clear right so and one more thing Java is a case-sensitive programming language you all know right so one is login with upper upper case another one is login with lower case that is not overloading because the names are different right just because that fact that Java is case sensitive easy right what is outcome of method overloading >> polymorphism compile time polymorphism certainly a question may come to your mind I understood what is polymorphism so what is the meaning of compile time we'll come back to that what is the meaning of compile time polymorphism what is the meaning of runtime polymorphism why what is the significance of the word called compile time that also we are going to discuss.
Can you take down some points, please?
Heading method overloading.
Method overloading.
Method overloading.
Having multiple methods in a class.
Having multiple methods in a class.
Having multiple methods in a class with the same name. Underline this point with the same name.
Having multiple methods in a class with the same name but but change in the signature but change in the signature. Having multiple methods in a class with the same name but change in the signature is called is called method overloading is called method overloading.
[snorts] It's called method overloading.
Just copy this. Change in the signature means change in the signature mean either there has to be a change in change in h the number of parameters or you can observe the screen if you Or there has to be a change in Or has to be a change in type of parameters or there has to be a change in H >> sequence or >> order of parameters.
Or there has to be change in the sequence or order of parameters.
[clears throat] Hi.
Copy.
Any questions? No question.
Copy everyone. Done. Take the next point.
In case in case if the method names are same in case if the method names are same and signatures are also same. In case if the method names are same.
In case if the method names are same and signatures are also same and signatures are also same.
In case if the method names are same and signatures are also same then it is considered as method duplication.
Then it is considered as method duplication.
Method duplication.
Hence compilation error.
Hence compilation error.
Hence compilation error.
Now have a look into this situation.
Would you like to copy this one as an example?
H copy.
Uh I think some discomfort here.
Copy this.
Make it fast. Fast.
>> [clears throat] >> Okay guys, done. All right, just observe.
Excuse me. Thumb up. Now just observe.
I'll demonstrate an example for error scenario.
One is void. Let's say the method name is meth or the method name is do something do something.
Okay. What to do?
Now observe having multiple methods in the same class.
Okay.
having multiple methods in the same class with the same name it's called same signature is called compilation error now now what I do is let's assume here it is integer k okay now is this compilation error >> why because here number of parameter one here number of parameter >> zero there is a change in the number of parameter oh okay sir Here it is doubled sir. Now now what?
Again number of parameters are same. In this case number of parameter is one and in this case number of parameter is one.
Though the number of parameters are same the data type of parameters are different. No no no sir. Here also number of parameters are same. Let's say for example integer j. Now observe s here it is k. Here it is J.
>> You understand?
>> The variable name does not matter. There is no importance to the variable name.
Okay. This is called method duplication.
Okay. For example, here it is int j as well as uh let's say boolean k.
Okay. And I'm going to write one more method here [snorts] where I'm going to change the sequence.
Observe it's boolean K and then int J it's called method over loading because here for so the first one is integer the second one is boolean whereas in this case the first one is the boolean and second one is integer remember one thing practically practically uh in the project wise we never overload our method just by changing the signature How does it matter for me which is first which is second? Are you able to understand this is only syntactically first one second one is the difference but practically we don't do that if you really want to overload overload with the number of parameters or data type of the parameters but if you're simply overloading two method a first is integer second is double in the second example first is double second is integer okay compiler will agree but realistically what is the fa it's of no use so you never see in any project you never see an overloaded method just in a change in the signature this is absolutely it. Okay, clear.
Okay. So now another example.
Think in this way.
Now here do something an integer.
Okay, here return type is void. Uh-oh.
Just observe how many methods? Two methods here. Return type is integer.
And I'm going to do something.
And then finally return 33.
Is it overloading? Yes. Hello, please answer.
>> Why? But return types are different. No, here it is. Here it is integer.
>> The return type does not matter. In method overloading the return type is not even considered. You only consider the method name and the signature. Take that note.
In case of method overloading, In case of method overloading, we don't consider In case of method overloading, we don't consider method return type. We don't consider the method return type and the access modifiers.
We don't consider the method return type and the access modifier.
>> [clears throat] >> What do you mean by this access modifier? Onto the left side of the method. Sometimes you use keywords like public, private, right? They're all called access modifiers. We don't consider them. We only consider the as I said here, we only consider the method name and the signature. The left side is not at all considered. Okay, copy this example. This is still considered as method overloading.
Copy this example. It is still method overloading chef. All is well.
>> Yes sir.
>> Okay.
copied.
Python supports >> not sure.
Now think about this situation.
Okay, don't get distracted. Just observe I have a class here. Method name is M.
Here method name is again met H.
Observe.
What about this one?
Huh?
I need an answer, guys. Analyze an answer.
It is called method duplication.
Hence, compilation error. Why method duplication?
Same method name, same signature. Only the return types are different. But return type is return type is not considered.
Mark it as an error. Teach copy compilation error. What is the reason?
>> Method duplication. Don't say that same method, same method. Say that as duplication. It's called method duplication.
[clears throat] understood.
Let's see another scenario.
Hey guys, everyone copied sir.
>> All right, just close the book. Observe here the another scenario. Okay, let's say the class name is test. I'm really going to take your test this time. Method name is add. Method name is add here. Let's say it says same or different. Here what I'm going to do is it's going to take two parameters integer I double D. Here integer D I interchange the sequence.
Observe correct.
Huh?
combination. You see here it is I and D >> variable name does not matter. What matters matters. Here also it is integer as well as double. Here it is integer as well as double. It is a biscuit program. Here it is I and D, D and I. Only we are interchanging or swapping the the variable names. The variable name does not matter. It's not at all given any importance. So this is called again method duplication hence compilation >> error.
I'll not ask you to write this because you have already this is also compilation error and it is considered as method duplication. So guys easy everyone understood I have given you real time example real world example right let's see another real world example take one point method overloading is used to achieve method overloading is used to achieve compile time polymorphism method overloading is used to achieve Compile time polymorphism is used to achieve compile time polymorphism because because method overloading represents because method overloading represents multiple forms of doing the same activity.
Method overloading represents multiple forms of doing the same activity or same task.
Multiple ways of doing the same activity or same multiple ways of doing the same activity or same task.
Correct.
So the job is same different forms of doing the same job inputs are different.
For example, morning you are drinking what you're drinking hot water probably with some little bit of lemon or something.
H evening also drink same water but instead of lemon you may add some whiskey in different inputs behavior only different polymer easy I will take you through last one more example please uh Let's say so let's say in an airplane for one topic I'm giving so many examples you should be happy actually oh those this is the way to show your happiness okay let's say you want to pay the bill you want to pay the bill let's say some 500 rupees you want to pay the bill excuse Can I say paying the bill is the behavior?
>> Pay the bill is the >> behavior.
Okay. Call it as pay the bill as the behavior.
Observe here. Pay the bill as a behavior. Sometimes I pay the bill by using up UPI.
Sometimes we pay the bill by using UPI.
Sometimes you pay the bill by using your card. Maybe credit card or debit card does not matter. It's a card. Sometimes I pay the bill by using internet banking or net banking.
Net banking.
Just observe here. You can pay the bill by using your UPI or you can pay the bill by using your card or pay the bill by using the net banking and another option is there valid but let's restrict ourself only to this. If you want to pay the bill by using the card, what information that you have to give?
Right? So if it is a card, you have to give the card number. You have to give the inputs as card number. Then expir date nothing but validity.
Then the three-digit CVB.
Okay.
Observe here the same way if you want to pay the bill by using net banking you select this and just pay now it will take you to the payment gateway where you have to enter the username and the password so how many data that I should enter in this case two data I have to enter two data what are the two datas that I have to enter here username and then password.
>> Password in the earlier case. How many data I should have entered?
>> Three data. I should have entered three data. Are you going to understand?
>> Whereas same if I want to make the if I want to pay the bill by using uh >> by using the UPI. Okay. You have to mention the UPI ID scan error or else the UPI what I would enter only one data could be my UPI ID.
Now tell me the data type of the UPI ID.
Maybe your phone number at the rate okay ici and other things can I consider it as string here what is the data type of card number >> long because it's a 16digit number expir date expir date of the card what is expir date let's say 05/29 >> 06/ something 30 so there is a since there is a slash involved can I consider it as a string okay is string and the CVV is a three-digit number. I'm going to consider it as integer. Same way.
Okay. So, if you want to make the pool using the net banking, you have to enter the username and the password as string and string.
String and string. So I have to write three methods in a class with the same name with the same name but change in the signature here I write one parameter for the same another method I write three parameters for the same method here I'm going to write four parameters okay now so I a class called As I tell how many methods I should write, >> three methods.
The table method why it's giving error.
>> Method duplication. Method duplication.
Here you can enter one input called UPI >> ID >> ID. So pay the bill by using >> pay the bill using >> UPI method in this case pay the bill by using >> card. So how many data?
>> Long card number >> and then >> string expiry >> date and then >> integer CV here.
>> What is that?
>> Net banking. Using the net banking.
So how much data?
>> Two.
>> Two. string user name.
>> String user name and then >> password >> string password.
Okay. So my behavior is same that's I'm paying the bill my mobile bill. So hence it is same name but change in the signature. This is a realistic example for >> method overloading.
Clear and it is a super important concept and often we use this in our project.
Method overloading is extremely common.
Clear? Copy this example.
Feeling cold.
Chill.
You'll have to come up with one more scarf.
Copy fast.
>> Okay.
Little cloudy weather. No, today >> Google she still in SQL hangover.
Hey there, please.
How was up?
How was that?
Guys listen this is a excuse me observe this is a perfectly possible interview question explain method overloading with real time example and real world example. So air is a real world example mobile unlock is a real world example the logging into the website is a real world example. What do you mean by real time example?
Real time example means in Java itself this concept is been implemented. Method overloading you can find method overloading inside Java. For example, see always remember lot of concepts of Java for example object- oriented concepts they ask you to explain that by giving real time example as well as real world example. Real world example is something like you know in day-to-day life where do you use these concepts?
Okay. And real time example means inside Java where do you find that a small example I'll give you this is perfectly possible interview question and often people ask this question okay for example there is something called system outprint okay now observe this Print ln is a method which is going to print the content on the new line or the next line. This print ln has just observe this How many methods are there? 1 2 3 4 5 6 7 8 9 10. Observe this thoroughly. How many overloaded methods are there? Print ln 10 overloaded print method is there.
So if you use the print ln method is it taking any parameter?
Hello please answer.
>> It is not taking any parameter means if someone ask you to define the signature it should say zero parameters. What does it do? It simply prints one empty line.
Clear? Whereas the other method is there print len which is taking one parameter which is that parameter boolean. The another one character character ar double float in long like that multiple print ln methods are there. There are 10 overloaded print ln methods are there.
How many print ln methods? 10 overloaded print ln method. Where this method is present are in which class it is present in a class called print stream. Can you see here the class name? It is present in a class called print stream. So inside the print stream class you can find 10 overloaded print method. This is a real time example of method overload loading. Now if you observe all these 10 methods their signatures are different.
The signatures are different. Are you able to understand?
That's the meaning. This is one. Take another note.
In print stream class in print stream class in print stream class P and S must be in uppercase. In print stream class we find we find 10 overloaded print ln methods. 10 overloaded print ln methods.
You are also trying to control that.
Right.
I hope everyone understood this concept.
I've given you real time example, real world example, possible tricky questions.
Clear? So the change in the signature, duplicating the signature, changing the written types, everything clear what is polymorphism? Polymorphism is derived from two words. One is called poly, another one is morphe. Par means many, morph means forms. Okay? Getting any work done in different forms that's a multiple forms is called.
All right, that's the topic. Any questions so far?
Krishna recording the class.
Turn off the laptop.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
🚀 BCS613C Compiler Design | Module 1 to 5 Schema Evaluation 🔥 | VTU 6th Sem 💯 #VTU #bcs613c #exam
Pranavaa-y4y
104 views•2026-06-02











