Skip to content

Instantly share code, notes, and snippets.

@indexer
Created January 8, 2014 10:48
Show Gist options
  • Save indexer/8314953 to your computer and use it in GitHub Desktop.
Save indexer/8314953 to your computer and use it in GitHub Desktop.
java overloading
class overload {
void test() {
System.out.println("No parameters");
}
// Overload test for one integer parameter.
void test(int a) {
System.out.println("a: " + a);
}
// Overload test for two integer parameters.
void test(int a, int b) {
System.out.println("a and b: " + a + " " + b);
}
// overload test for a double parameter
double test(double a) {
System.out.println("double a: " + a);
return a*a;
}
}
class overload {
public static void main(String args[]) {
OverloadDemo ob = new OverloadDemo();
double result;
// call all versions of test()
ob.test();
ob.test(10);
ob.test(10, 20);
result = ob.test(123.2);
System.out.println("Result of ob.test(123.2): " + result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment