• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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
 
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic