• 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

 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the follow are true statements?


(1) An anonymous class can extend only the Object class
(2) An anonymous class can not implement an interface
(3) An anonymous class can be abstract
(4) An anonymous class is implicitly final-answer
(5) An anonymous class can be static
(6) The class instance creation expression for an anonymous class must never include parameters
(7) An anonymous class must declare at least one constructor
(8) None of the above

I think the answer is 4 & 6. But the real answer is 4 only. Why 6 is not a right answer ?
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nevermind to my original response....


i think you are right and that the test question should allow for two choices(4 and 6), not just the one.
[ September 07, 2007: Message edited by: Michael Raymond Jr. ]
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here s a quick code going through which hopefully will make your doubts about point(6) clear....



Though, If the class you are extending by annonymous class doesn't have any constructor other than the default one, you can not define any new constructor etc etc.... as you already know.
[ September 07, 2007: Message edited by: B Misra ]
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Misra,
Thanks. So 4 is only the answer. Am I right?
 
B Misra
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes as if the class being extended have constructor with arguments, you can use those constructor while calling 'new' and defining annonymous class.....

you might want to run that code & try it out yourself.... will help you understand more clearly....
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See page 308 Khalid Mughal 1.4 Section Extending an Existing Class
 
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this 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