Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

anonymous inner class question

 
Francis Palattao
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given: From K & B Master Exam



which 2 create an anonymous inner class from within class Bang

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 given C & D

I do not understand how C works because when I try to just create a class like this it doesn't work. Can someone please explain.

Class A{
"Foo";
}
 
Joseph Maddison
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw that too - the { "Foo" }; part does not compile, so it should not have been a correct answer. I believe this is an error in the exam. This probably should go in the Errata forum...

jdmaddison
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you copied the answers right?

c will create an anonymous class if you remove the String and leave the ;
d is fine though.

With the String in place in c you will get a compile error.
 
Jay Pawar
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes that is wrong answer it should be


Bing b = new Bing("Foo"){};

 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you search this forum for "bing bang" you will see that the general opinion is that it is a typo.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic