GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from K&B mock test | Anonymous inner classes 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 "Question from K&B mock test | Anonymous inner classes" Watch "Question from K&B mock test | Anonymous inner classes" New topic
Author

Question from K&B mock test | Anonymous inner classes

Nidhi Bangur
Greenhorn

Joined: Sep 12, 2003
Posts: 19
Hi,
Yesterday, I took the mock test included in the CD with Kathy and Bert's book. I came across a question which tested my knowledge of anonymous inner classes.
The question was as follows (The words might not be exactly similar here):
___________________________________________________________________________
Given the following code definition, which two declarations of anonymous inner classes inerted at line 1, will compile successfully?
class Bing{
Bing(String s){
}
Bing(){
}
}
class Bang extends Bing{
Bang(String s){
super(s);
}

Bang(){
super();
}

// Line 1
}
___________________________________________________________________________
There were 2 correct answers to this question which are as follows:
1) Bing b = new Bang(){}
2) Bing b = new Bing(){"Foo";}
I have no problem with option 1 but how is option 2 correct here? I have tried inserting option 2 at line 1 and compiling the code but it doesn't compile and I am sure that this is not a correct syntax of instance initializer as well.
Has anybody else come across this question? Is the question wrong or if the option 2 is still correct, Please let me know how?
Thanks,
Nidhi.
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
2) Bing b = new Bing(){"Foo";}
Are you sure that's one the possible answers? I didn't come across to this possible answer.
[ October 02, 2003: Message edited by: Andres Gonzalez ]

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Nidhi Bangur
Greenhorn

Joined: Sep 12, 2003
Posts: 19
Yes Andres, After your message I rechecked the question. The answers given are the same except that I missed one ";" at the end of both options while writing them here.
I am myself surprised as to how can it be the answer? Any comments from Bert?
Thanks,
Nidhi.
Cathy Bryant
Greenhorn

Joined: Sep 24, 2003
Posts: 5
I just did that same test, and have the same question. I tried running that code, and it doesn't compile. I don't see how "Foo" can be used in the class definition.
Steve Lovelace
Ranch Hand

Joined: Sep 03, 2003
Posts: 125
It's a typo. You can find a discussion of it here: link
[ October 02, 2003: Message edited by: Steve Lovelace ]

The Inner that is named is not the true Inner.
 
GeeCON Prague 2014
 
subject: Question from K&B mock test | Anonymous inner classes