This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

anonymous inner class question  RSS feed

 
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";
}
 
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
 
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.
 
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"){};

 
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!