This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes anonymous? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "anonymous?" Watch "anonymous?" New topic
Author

anonymous?

srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
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???


Thanks & Regards<br /> <br />-Srikanth
Joan Pujol
Ranch Hand

Joined: Oct 12, 2005
Posts: 54
The compiler says that this is not possible
Akshay Kiran
Ranch Hand

Joined: Aug 18, 2005
Posts: 220
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?


"It's not enough that we do our best; sometimes we have to do<br />what's required."<br /> <br />-- Sir Winston Churchill
Ray Horn
Ranch Hand

Joined: Oct 20, 2005
Posts: 39
so why cant it have?

anonymous inner class is an instance of an class. Static code cannot access instance members.
Abhijit Sontakey
Ranch Hand

Joined: Sep 26, 2005
Posts: 67
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.
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
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
agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
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
 
jQuery in Action, 2nd edition
 
subject: anonymous?
 
Similar Threads
anonymous class and static
a question of anonymous class
Anonymous class
Doubt on Anonymous class
anonymous inner class