Method Overloading in Java
Hello friends; Hitesh is here, today I will give a simple example and definition of Method Overloading in Java.If a class has multiple methods by the same name but different parameters, it is known as Method Overloading. If two or more method in a class has the same name but different parameters, it is known as method overloading.
Example of Method Overloading in Java
class OverloadingDemo
{
void sum(int a,int b)
{
System.out.println(a+b);
}
void sum(int a,int b,int c)
{
System.out.println(a+b+c);
}
public static void main(String args[]){
OverloadingDemo obj=new OverloadingDemo();
obj.sum(20,20,20);
obj.sum(10,10);
}
}
Output:
60
20
No comments:
Post a Comment