Question from:
Java 2 Sun Certified Programmer & Developer. Kathy Sierra; Bert Bates. Inner Classes -> question 5
Hi! I don't know if there's an error in the question below, probably I'm missing something.
Given the following,
which statement, inserted at line 7 (in the book is line 5 Oo), creates an instance of Bar?
A. Foo.Bar b = new Foo.Bar();
B. Foo.Bar b = f.new Bar();
C. Bar b = new f.Bar();
D. Bar b = f.new Bar();
E. Foo.Bar b = new f.Bar();
The correct answer is B, but I think D is also correct.
The book says that: "D is incorrect because it doesn’t use the enclosing class name in the reference variable declaration."
I don't agree with it! Both ways "creates an instance of Bar"! I tested and it compiles and runs fine!
Please, correct if I'm wrong.