Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Helllp..... Anon Class - Kathy & Bert's CD

 
Padma Raman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I ahve come across this problem in Kathy & Bert's CD. I could not understand a bit and I am getting error when i try to compile the program also. Can anyone explain?
Question: Given the following:

Which two would create and anonymous inner class from within the class Bang?
Choices:
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 : C & D.
I feel answer A and D are correct; C is not even working for me!!!
Please explain. Moreover thsi software is not good at all. It doesn't let me do even copy and paste at all. It even declares that i failed when scored 77%.

Regards,
Raman
Edited by Corey McGlone: Added CODE Tags
[ March 11, 2004: Message edited by: Corey McGlone ]
 
Mel Edwards
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer C is indeed incorrect. It has a typo. For the discussion see here:
http://www.coderanch.com/t/241104/java-programmer-SCJP/certification/comprehensive-exam-kathy-Bert-book
Answer A is wrong because it is trying to refer to a superclass using a variable declared as a subclass. It would work fine the other way around, (like answer D in fact) but not this way.
Finally you've got a small transcription error in your code. It should be:
Bang(String bangS) {super(bangS);}
(note the punctuation)
 
Padma Raman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks a lot.
Regards,
Raman
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic