Thursday, April 12, 2012

Java Think Twister

What will be the output of the following code? And explain how?

public class Foo {
private static Foo instance = new Foo();
private static final int DELTA = 6;
private static int BASE = 7;
private int x;

    private Foo() {
            x = BASE + DELTA;
    }

    public static void main(String... argv) {
        System.out.println(Foo.instance.x);
    }

}

Options:
a) 13
b) 6
c) 7
d) 0

No comments:

Post a Comment