aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Anonymous Inner class from K&B mock exam 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 from K&B mock exam" Watch "Anonymous Inner class from K&B mock exam" New topic
Author

Anonymous Inner class from K&B mock exam

K Anshul
Ranch Hand

Joined: May 19, 2004
Posts: 71


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 ]
arnel nicolas
Ranch Hand

Joined: Dec 16, 2003
Posts: 149
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

Joined: May 19, 2004
Posts: 71
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?
Beny Na
Ranch Hand

Joined: May 26, 2004
Posts: 159
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.
Chris Allen
Ranch Hand

Joined: Feb 01, 2003
Posts: 127
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

Joined: May 19, 2004
Posts: 71
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.
 
subject: Anonymous Inner class from K&B mock exam