/* * ============================================================================== * DemoTryPolymorphism.java: Polymorphism is the capability of an action * or method to do different things based on the details of object that it is * acting upon. This is the third basic principle of object oriented programming. * * Java can support various forms of polymorphism. The simplest form is * overloaded methods. That is, methods with the same name signature but either * a different number of parameters or different types in the parameter list. * * Written By: Mark Austin October 2005 * ============================================================================== */ public class DemoPolymorphism { // Version 1: Method doSomething() has no args ... public static void doSomething() { System.out.println("*** In doSomething() "); System.out.println(" Version has no args!! "); } // Version 2: Method doSomething() has one arg of type float! public static void doSomething( float fX ) { System.out.println("*** In doSomething() "); System.out.println(" Version has one argument of type float!"); } // Version 3: Method doSomething() has one arg of type double! public static void doSomething( double dX ) { System.out.println("*** In doSomething() "); System.out.println(" Version has one argument of type double!"); } // --------------------------------------------------------- // main method : this is where the program execution begins. // --------------------------------------------------------- public static void main ( String [] args ) { float fX = 1.0f; double dY = 1.0; // Call doSomething() methods in a variety of ways .... System.out.println("*** In main(): call doSomething() for the first time" ); doSomething(); System.out.println("*** In main(): call doSomething() again" ); doSomething( dY ); } }