Overloaded.java


Below is the syntax highlighted version of Overloaded.java from §2.1 Static Methods.


/******************************************************************************
 *  Compilation:  javac Overloaded.java
 *  Execution:    java Overloaded
 *
 ******************************************************************************/

public class Overloaded {

    public static void f(int x, double y) {
        StdOut.println("f(int, double)");
    }

    public static void f(double x, int y) {
        StdOut.println("f(double, int)");
    }

    public static void f(double x, double y) {
        StdOut.println("f(double, double)");
    }

    public static void main(String[] args) {
        f(1.0, 17);
        f(1, 17.0);
        f(1.0, 17.0);
        //// f(1, 17);        // compile-time error: reference to f is ambiguous
    }

}


Copyright © 2000–2017, Robert Sedgewick and Kevin Wayne.
Last updated: Fri Oct 20 14:12:12 EDT 2017.