Java examples for Object Oriented Design:Method Overloading
Overloaded method declarations.
public class Main { // test overloaded square methods public static void main(String[] args) {/*from w w w. j a v a2s.c o m*/ System.out.printf("Square of integer 7 is %d%n", square(7)); System.out.printf("Square of double 7.5 is %f%n", square(7.5)); } // square method with int argument public static int square(int intValue) { System.out.printf("%nCalled square with int argument: %d%n", intValue); return intValue * intValue; } // square method with double argument public static double square(double doubleValue) { System.out.printf("%nCalled square with double argument: %f%n", doubleValue); return doubleValue * doubleValue; } }