It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes anonymous inner class question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "anonymous inner class question" Watch "anonymous inner class question" New topic
Author

anonymous inner class question

Francis Palattao
Ranch Hand

Joined: Sep 22, 2004
Posts: 91
Given: From K & B Master Exam



which 2 create an anonymous inner class from within class Bang

A. Bang b = new Bing("Foo"){};
b. Bing b = new Bing (343){};
c. Bing b = new Bing(){"Foo";};
d. Bing b = new Bang(){};
e. Bing b = new Bing.Bang("Foo"){};

answer given C & D

I do not understand how C works because when I try to just create a class like this it doesn't work. Can someone please explain.

Class A{
"Foo";
}


SCJP 1.4 <br />SCWCD 1.4 (preparing)<br />SCBCD 1.3 (coming soon)
Joseph Maddison
Ranch Hand

Joined: Nov 04, 2004
Posts: 53
I saw that too - the { "Foo" }; part does not compile, so it should not have been a correct answer. I believe this is an error in the exam. This probably should go in the Errata forum...

jdmaddison
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Are you sure you copied the answers right?

c will create an anonymous class if you remove the String and leave the ;
d is fine though.

With the String in place in c you will get a compile error.
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
Yes that is wrong answer it should be


Bing b = new Bing("Foo"){};



Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
If you search this forum for "bing bang" you will see that the general opinion is that it is a typo.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: anonymous inner class question