what is overload in java code example
Example 1: What's method overloading
Overloading mean same method name and different parameter,
it can happen in same class. it's a feature that
allows us to have more than one method with same name.
Example: sort method of Arrays class
Arrays.sort(int[] arr)
Arrays.sort(String[] arr)
....
Method overloading improves the reusability and readability.
and it's easy to remember
(one method name instead of remembering multiple method names)
Example 2: exp on mathed overlading in java
class DisplayOverloading2
{
public void disp(char c)
{
System.out.println(c);
}
public void disp(int c)
{
System.out.println(c );
}
}
class Sample2
{
public static void main(String args[])
{
DisplayOverloading2 obj = new DisplayOverloading2();
obj.disp('a');
obj.disp(5);
}
}