• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question from K&B mock test | Anonymous inner classes

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Nidhi Bangur
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a typo. You can find a discussion of it here: link
[ October 02, 2003: Message edited by: Steve Lovelace ]
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic