This question is derive from SCJP5.0 K&B book.
Given:
1 public class Foo{
2 Foo(){System.out.print("foo");}
3 class Bar{
4 Bar() {System.out.print("bar");}
5 public void go(){System.out.print("hi");}
6 }
7 public static void main(
String[] args){
8 Foo f = new Foo();
9 f.makeBar();
10 }
11 void makeBar(){
12 (new Bar() {}).go();
13 }
14 }
What is the result?
A. Compilation fails.
B. An error occurs at runtime.
C. foobarhi
D. barhi
E. hi
F. foohi
The answer is C. foobarhi
My question is;
At the line 12 why it not written to (new Bar() {}
;).go();
I think anonymous inner class must follow by ';' in the plain-old one and follow by ');' for argument anonymous. But, why this given code is not follow this rule.