Understanding OOP Concepts: Method Overloading
Method Overloading is a technique that allows a class multiple methods having the same name but different in parameters. It’s like constructor overloading. This technique is also called compile-time polymorphism or static binding or early binding.
There are different ways to overload a method in Java. They are:
Number of parameters
This method overloading is done by having different number of parameters. The example:
class MyClass {
public void add(int i) {
// code
}
public void add(int i, int j) {
// code
}
}
Data type of parameters
This method overloading is done by having different data types of parameters. The example:
class MyClass {
public void add(int i, int j) {
// code
}
public void add(int i, float j) {
// code
}
}
Sequence of Data type of parameters
This method overloading is done by having sequence of data type of parameters. The example:
class MyClass {
public void add(int i, float j) {
// code
}
public void add(float i, int j) {
// code
}
}
Md Obydullah
Software Engineer | Ethical Hacker & Cybersecurity...
Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.