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.


About this entry