Chris Lamb

Java Quiz

public class Overload {
    public static void main(String args[]) {
        int result = foo(new B(), new B());
        System.out.println(result);
    }

    public static int foo(A a, B b) { return 1; }
    public static int foo(B b, A a) throws Exception { return 2; }

    static class A { }
    static class B extends A { }
}

Without using a compiler (using the JLS and JLS report is allowed), answer the following:

  1. Does this code compile?
  2. If yes - what is the result from running the program?
  3. If no - why not? List all errors.

Answers on a postcard.


Chris Lamb is a freelance software developer and the current Debian Project Leader. You can read other posts by me, see software I have written or read more about me. You can also follow me @lolamby.


Planets: ALUG UWCS WUGLUG

Monday 9th April 2007


Four comments