File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Urgent on static Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Urgent on static" Watch "Urgent on static" New topic

Urgent on static

Ann , Varghese

Joined: Oct 16, 2000
Posts: 13
Can any of you clearly list the limitations /accessibility of static modifiers & variables? Let me make it more clear in the exam point of view. While going through a code what important aspects about static modifiers & variables should we be alert of???
This is kind of important.
Milind Mahajan
Ranch Hand

Joined: Oct 23, 2000
Posts: 77
This is what I know :
When you apply static modifier for a member of a class, it means that the member is not associated with a particular instance of the class it is contained. Rather, it is associated with the class itself.
static modifier can be applied to :
1. Inner class
2. Methods
3. Variables
4. Free floating blocks
1. static inner classes :
a. Cannot access instance variables of outer class.
b. Are not associated with instance of outer class unlike
nonstatic inner classes.
c. Are as good as top level classes with modified naming
d. Can contain static variables unlike nonstatic inner
2. static methods :
a. Cannot access instance variables of the class.
b. Do not have "this" reference.
c. I think they don't have "super" reference either.
d. Cannot be overridden to be nonstatic.
e. Do not participate in dynamic binding.
f. Can contain a nonstatic/static inner class.
g. Cannot be abstract.

3. static variables :
a. Initialized when the class is loaded into JVM.
b. Are shared by all instances of the class.
4. static blocks :
a. Are executed only once : when the class is loaded into JVM.
b. Can access only static methods and variables.
c. Are executed in the order of their definition in the class.
You have asked to list the aspects of static modifier from exam point of view. Actually I am yet to take SCJP. But I think we should know all these points. We can understand all these points well if we do some experiments with them.
Well, that is all I know. Anybody, please correct me if I am wrong. Add any other details you know.
ravi chan

Joined: Nov 02, 2000
Posts: 11
Good Job Milind. If I am right you can add :
Cannot declare a static variable inside an instance method
Mapraputa Is
Leverager of our synergies

Joined: Aug 26, 2000
Posts: 10065
Wow... What a great job, Milind!

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Santosh Jaiswal

Joined: Oct 04, 2000
Posts: 26
Great job!!!
Milind Mahajan
Ranch Hand

Joined: Oct 23, 2000
Posts: 77
Thanks a lot all of you.
Jon Aryan

Joined: Oct 06, 2000
Posts: 22
Static variables are garbage collected when the class is unloaded !!! unlike the instance variables, which are garbaged collected when there are no more reference to the object. rite ?
Bin Zhao
Ranch Hand

Joined: Oct 04, 2000
Posts: 73
I have doubt about the following:
2. static methods :
f. Can contain a nonstatic/static inner class.
Can a static method contain a static inner class?
I don't think so.
Static inner class can only be member class.They can not be defined in a method.
satishind Reddy
Ranch Hand

Joined: Oct 17, 2000
Posts: 33
One more point You cannot declare locale Inner class as a static. And Locale Inner class will not have any static members.
Milind Mahajan
Ranch Hand

Joined: Oct 23, 2000
Posts: 77
You both are right Bin and Satish.
Sorry for the error.
I agree. Here's the link:
subject: Urgent on static
Similar Threads
How should I answer the questions on the exam.
instance field
Static Final Transient
Object Arrays