public class testuu{
public static void main(String as[]) throws Throwable {
System.out.println("sum is: " + sum(14,0) + " sum of three params is: " + sum(1,2,3));
}
public static int sum(int a, int b) throws Exception {
int sum = a+b;
return sum;
}
private static int sum(int a, int b, int c) {
int sum = a+b+c;
return sum;
}
}
Output:
sum is: 14
sum of three params is: 6
//In above example we have two method with same name as "sum" but we have pass different parameters which is an perfect example for method overloading or polymorphism.
public static void main(String as[]) throws Throwable {
System.out.println("sum is: " + sum(14,0) + " sum of three params is: " + sum(1,2,3));
}
public static int sum(int a, int b) throws Exception {
int sum = a+b;
return sum;
}
private static int sum(int a, int b, int c) {
int sum = a+b+c;
return sum;
}
}
Output:
sum is: 14
sum of three params is: 6
//In above example we have two method with same name as "sum" but we have pass different parameters which is an perfect example for method overloading or polymorphism.
No comments:
Post a Comment