1.

What will be the output of the program?

public class Foo { Foo() { System.out.print("foo"); } class Bar
{ Bar() { System.out.print("bar"); } public void go() { System.out.print("hi"); }
} /* class Bar ends */ public static void main (String [] args) { Foo f = new Foo(); f.makeBar(); } void makeBar() { (new Bar() {}).go(); }
}/* class Foo ends */

A. Compilation fails.
B. An error occurs at runtime.
C. It prints "foobarhi"
D. It prints "barhi"
Answer» D. It prints "barhi"


Discussion

No Comment Found

Related MCQs