This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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.
 
money grubbing section goes here:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!