Skip to content
Software Testing Material Logo
  • Blog
  • TutorialsExpand
    • Expand
      • Manual Testing
      • Selenium
      • TestNG
      • Maven
      • Jenkins
      • Framework
    • Expand
      • Java
      • Agile
      • API Testing
      • Postman
      • SQL
      • VBScript
  • ToolsExpand
    • Recommended ToolsExpand
      • TestCollab
      • PractiTest
      • Testiny
      • Qase
      • Test Lodge
      • Testsigma
    • Expand
      • Postman
      • ActiveBatch
      • Redwood
      • Tidal Software
      • JScape
    • Best ToolsExpand
      • Enterprise Job Scheduler
      • Test Management
      • Automation Testing
      • Codeless Testing
      • Selenium Alternatives
      • Bug Tracking
      • Mobile App Testing
      • Cross Browser Testing
    • Expand
      • API Testing
      • Unit Testing
      • Regression Testing
      • Continuous Testing
      • Functional Testing
      • Penetration Testing
      • Performance Testing
      • View All
  • Interview Q & AExpand
    • Expand
      • Selenium
      • TestNG
      • Test Framework
      • Explain Framework
      • API
      • SOAP
      • Protractor
    • Expand
      • Manual Testing
      • Software QA
      • Agile
      • JIRA
      • Java
      • Python
      • SQL
  • Free Resources
  • QuizExpand
    • Software Testing Quiz
    • Automation Testing Quiz
    • Selenium Quiz
    • Performance Testing Quiz
    • ISTQB Quiz
    • Java Quiz
    • SQL Quiz
    • JIRA Quiz
  • Jobs
Software Testing Material Logo
Home / Java / Method Overloading In Java

Method Overloading In Java

ByRajkumar Updated onJune 11, 2025

A class having multiple methods with same name but different parameters is called Method Overloading

There are three ways to overload a method.

1. Parameters with different data types

myMethod(int a)
myMethod(String a)

2. Parameters with different sequence of a data types

myMethod(int a, String b)
myMethod(String a, int b)

3. Different number of parameters

myMethod(int a)
myMethod(int a, int b)

Earlier we have seen method signature. At compile time, Java knows which method to invoke by checking the method signatures. So this is called compile time polymorphism or static binding.

Let’s see some practical example for better understanding.

1. Parameters with different data types

package methodOverloadingDiffDataTypes;

public class MethodOverloadingDiffDataTypes {

	public void methodOne(int a){
        System.out.println(a);
    }
    
	public void methodOne(String a)
    {
       System.out.println(a);
    }	
	
	public static void main(String[] args) {

		MethodOverloadingDiffDataTypes obj = new MethodOverloadingDiffDataTypes();
		
		obj.methodOne(10);
		obj.methodOne("I am a String");
		
	}
}

Output:

10
I am a String

2. Parameters with different sequence of a data types

package methodOverloadingDiffSequenceDataTypes;

public class MethodOverloadingDiffSeqDataTypes {

	public void methodOne(int a, String b){
        System.out.println(b);
    }
    
	public void methodOne(String a, int b)
    {
       System.out.println(a);
    }	
	
	public static void main(String[] args) {

		MethodOverloadingDiffSeqDataTypes obj = new MethodOverloadingDiffSeqDataTypes();
		
		obj.methodOne(1, "Int and String");
		obj.methodOne("String and Int", 2);
		
	}
}

Output:

Int and String
String and Int

3. Different number of parameters