Method Overloading In Java Example
Chapter:
Inheritance
Last Updated:
20-07-2016 03:21:29 UTC
Program:
/* ............... START ............... */
public class JavaMethodOverloading {
void val(int a, int b) {
System.out.println(a + b);
}
void val(int a, int b, int c) {
System.out.println(a + b + c);
}
public static void main(String args[]) {
JavaMethodOverloading obj = new JavaMethodOverloading();
obj.val(10,20,30);
obj.val(20, 20);
}
}
/* ............... END ............... */
Output
Notes:
-
If a class have multiple methods by same name but different parameters,it is known as Method Overloading.
- Method overloading is one of the ways through which java supports polymorphism.
- If two or more method have same name and same parameter list but differs in return type are not said to be overloaded method.
Tags
Method Overloading, Java