... MethodOverload.java
 2// Overloaded method declarations.
 3
 4 public class MethodOverload {
 5   // test overloaded square methods
 6   public static void main(String[] args) {
 7      System.out.printf("Square of integer 7 is %d%n", square(7));
 8      System.out.printf("Square of double 7.5 is %f%n", square(7.5));
 9   }
10
11   // square method with int argument 
12   public static int square(int intValue) {
13      System.out.printf("%nCalled square with int argument: %d%n",
14         intValue); 
15      return intValue * intValue; 
16   }
17
18   // square method with double argument 
19   public static double square(double doubleValue) {
20      System.out.printf("%nCalled square with double argument: %f%n",
21         doubleValue); 
22      return doubleValue * doubleValue; 
23   }
24}
Called square with int argument: ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.