public class MethodOverload
1: // Fig. 6.13: MethodOverload.java
2: // Overloaded method declarations.
3:
4: public class MethodOverload
5: {
6: // test overloaded square methods
7: public void testOverloadedMethods()
8: {
9: System.out.printf( "Square of integer 7 is %d\n", square( 7 ) );
10: System.out.printf( "Square of double 7.5 is %f\n", square( 7.5 ) );
11: } // end method testOverloadedMethods
12:
13: // square method with int argument
14: public int square( int intValue )
15: {
16: System.out.printf( "\nCalled square with int argument: %d\n",
17: intValue );
18: return intValue * intValue;
19: } // end method square with int argument
20:
21: // square method with double argument
22: public double square( double doubleValue )
23: {
24: System.out.printf( "\nCalled square with double argument: %f\n",
25: doubleValue );
26: return doubleValue * doubleValue;
27: } // end method square with double argument
28: } // end class MethodOverload
29:
30: /**************************************************************************
31: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
32: * Pearson Education, Inc. All Rights Reserved. *
33: * *
34: * DISCLAIMER: The authors and publisher of this book have used their *
35: * best efforts in preparing the book. These efforts include the *
36: * development, research, and testing of the theories and programs *
37: * to determine their effectiveness. The authors and publisher make *
38: * no warranty of any kind, expressed or implied, with regard to these *
39: * programs or to the documentation contained in these books. The authors *
40: * and publisher shall not be liable in any event for incidental or *
41: * consequential damages in connection with, or arising out of, the *
42: * furnishing, performance, or use of these programs. *
43: *************************************************************************/