Method Overloading Function
overloading or method overloading is the ability to create
multiple methods of the same name with different implementations.
It is a
feature that allows a class to have two or more methods having same name but different number of arguments or different argument types
or different lines of code , calculations etc inside the methods with same
name.
If a class have multiple methods by same name but different parameters, it is known as Method Overloading.
We can overload main() method also .
Yes, by method overloading. You can have any number of main methods in a class by method overloading.
Method overloading increases the readability of the program.
There are three ways to overload method in java
1. By changing number of arguments
2. By changing the data type
3. By changing the sequence of data type of parameters.
Method Overloading is NOT possible by changing the return type of the method.
Method overloading is also known as Static Polymorphism.
Key Points:
1. Static Polymorphism is also known as early binding or compile time binding as it happens at compile time.
2. Method overloading is an example of static binding because binding of method call to its definition happens at Compile time.
Constructor method can also be oveloaded same way.
Constructor overloading allows a class to have more than one constructors having different argument lists.
Example :
class OverLoadDataTypes
{
public void see1(char a)
{
System.out.println(a);
}
public void see2(int a)
{
System.out.println(a);
}
}
class UsingMethods
{
public static void main(String args[])
{
OverLoadDataTypes obj = new OverLoadDataTypes();
obj.see('l');
obj.see(7);
}
}
- Abstraction
- Method
Overriding
- Method
Overloading
- Instance
Variables
- Java
Applets
- Pop
ups and Alerts
- Absolute path
- Relative path
- Annotations
Selenium Webdriver Browser Commands - Absolute path Vs
Relative path
- Selenium Webdriver Pop
ups and Alerts
- Testng Annotations -
part 1
- Object
Models in QTP - Part 1
Agile Testing Methodology - Extreme Programming
and customer satisfaction
- Mobile testing - What
are the Challenges in mobile testing & Strategies we can follow to
deal with them
- Crowdsource testing -
Crowdtesting
- Model-based testing
(MBT)
- Big Data Testing
- Cloud Testing
- TDD Test Driven
Development
- Verification vs
Validation
- Software Testing
Interview Questions - Mock Test CSTE / ISTQB
- Software testing types
- Risk Management
Comments
Method Overloading in Java Nice post, thanks on Method Overloading in Java - Easy Explanation with Examples