View RSS Feed

Java Object

What is overloading in java

Rate this Entry
by , 04-26-2012 at 06:40 PM (990 Views)
Two or more than two methods could be defined in Java, within similar class which has similar names with different parameter declarations. In this particular case, methods are overloaded and this is known as method overloading. Method overloading is method by which polymorphism is implemented.

Sample program of overloading:
Java Code:
class Overloading {
void test() {
System.out.println("No parameters");
}

void test(int a, int b) {
System.out.println("a and b: " + a + " " + b);
}

void test(float a) {
System.out.println("Inside test(double) a: " + a);
}
}
class Overload {
public static void main(String args[]) {
Overloading ob = new Overloading();
int i = 88;
ob.test();
ob.test(10, 20);
ob.test(i); 
ob.test(123.2); 
}
}

Submit "What is overloading in java" to Facebook Submit "What is overloading in java" to Digg Submit "What is overloading in java" to del.icio.us Submit "What is overloading in java" to StumbleUpon Submit "What is overloading in java" to Google

Categories
Overloading

Comments