aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B inner classes Q.2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B inner classes Q.2" Watch "K&B inner classes Q.2" New topic
Author

K&B inner classes Q.2

Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504


Which create an anonymous inner class from within class Bar? (Choose all that apply.)

A. Boo f = new Boo(24) { };
B. Boo f = new Bar() { };
C. Boo f = new Boo() {String s; };
D. Bar f = new Boo(String s) { };
E. Boo f = new Boo.Bar(String s) { };

the answer they say is B and C.
B is fine with me but how come C is a correct answer its creating an anonymous class from within Boo not from Bar.

SCJP 1.6 96%
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
Because you are inserting the code in the code for the Bar class. Since the code is in the Bar class, it will be an anonymous inner class in Bar.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
oh yes , I didn't see that......thanks
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Because the line is inserted in the class Bar . The other possibilities are not possible because they use an argument in the constructor which is not possible for an anonymous class.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B inner classes Q.2