Created
January 8, 2014 10:48
-
-
Save indexer/8314953 to your computer and use it in GitHub Desktop.
java overloading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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