• 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

Anonymous Inner class from K&B mock exam

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I can understand D but i can't understand C.
How does it create an anonymous inner class.
[ June 23, 2004: Message edited by: Anshul Kayastha ]
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i dont have the K&B book but basing from the code
i have the following doubtful explanation.Hope you dont mind.

1) for Letter A = you cannot assign class Bing to class Bang because
class Bing is a superclass. It will cause a runtime error.

2) for Letter B = the class Bing does not have a constructor that takes an int parameter.

3) for Letter C = its obviously correct.

4) for Letter D = it creates an anonymous class of type Bang and stores it to
a type of class Bing. It is perfectly legal because Bang is a subclass of class Bing.

cheers,
arnel
 
K Anshul
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying

3) for Letter C = its obviously correct.



That is what I wanted to know.
Why is C right?
Is it legal to write soemthing like "Foo". Shouldn't it be a parameter or something.
I have never seen something like

{ //curly brace
"Foo";
}//curly brace ends


What does this code mean?
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi..i got an error when try to compile that..

class Bing {
Bing(String s){} Bing() {}}

class Bang extends Bing {
Bang() {}
Bang(String bangS)
{ super(bangS); }
Bing b = new Bing(){ "Foo" }; // this line won't compile

//insert code here }

}


i do not understand why C is correct..and the java compiler show error for that.
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible that answer C should have been originally typed as:


to match the Bing constructor that takes a String?
 
K Anshul
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chris Allen:
Is it possible that answer C should have been originally typed as:


to match the Bing constructor that takes a String?



Might be. I saw the question in K&B mock exam
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic