• 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?

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An anonymous inner class can have a static initializer . Is this statement true or false ?

Options :

a . true
b . false

initializers has nothing to do with the name ...so why cant it have???
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The compiler says that this is not possible
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by srikanth reddy:
An anonymous inner class can have a static initializer . Is this statement true or false ?

Options :

a . true
b . false

initializers has nothing to do with the name ...so why cant it have???


What sense does it make to have a static initializer in an anonymous inner class?
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

so why cant it have?


anonymous inner class is an instance of an class. Static code cannot access instance members.
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Anonymous class is a local member of a method or constructor. It is not a class level member. Just as a local method variable cannot be static a anonymous class reference cannot be declared static.
 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Static initializer-No ..

reasons have been given in the posts....


instance initializers-Yes...


The non-static initializer is the only way to do initialization in an anonymous inner class, as those can't have constructors.




Regards
 
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just Remember one very important point that static construct i.e. static variable,initializer,method etc are top level construct so they can appear at toplevel class scope or nested within a static construct.
Hope it helps
reply
    Bookmark Topic Watch Topic
  • New Topic