• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Anonymous class...please help

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Select the two correct answers.
a. The method labeled (1).
b. The method labeled (2).
c. The method labeled (3).
d. The method labeled (4).
e. The method labeled (5).

Answer d and e.The syntax of the anonymous class in the method labeled (2) is not correct, as the parameter list is missing

Please explain to me the code #2.what is missing there?what is the correct one?

thanks
[ April 23, 2008: Message edited by: Ben Souther ]
 
vinal sen
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forgot to say that I saw this code on the book written by Khalid Mughal.

thanks.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for label #2 you should use new IntHolder() <--- this is the parameter list
 
vinal sen
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh! tricky one. thank you.
 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happen to option 1 and 3, it is syntaxically correct..

Can someone pls explain me this
[ April 21, 2008: Message edited by: Dinesh Tahiliani ]
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dinesh Tahiliani,
anonymous class cannot access local variables that are not final.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi vinal,

Whenever you post mock questions to Javaranch, it's important that you
QuoteYourSources.
If a mock question shows up without a valid source that can be verified, we need to remove it.

Thank you for your consideration in this matter.
-Ben
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vinal sen:
Forgot to say that I saw this code on the book written by Khalid Mughal.

thanks.



vinal sen,

I owe you an apology.
I did not notice this reference when I removed your question.
Sorry for any inconvenience.
-Ben
 
Ranch Hand
Posts: 241
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tricky indeed. Bloody hell, even after reading the answer, I only noticed the missing brackets after staring at it for about 5 minutes!
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic