aspose file tools*
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
Author

Urgent on static

Ann , Varghese
Greenhorn

Joined: Oct 16, 2000
Posts: 13
Hi,
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.
Thanks
Milind Mahajan
Ranch Hand

Joined: Oct 23, 2000
Posts: 77
Hi,
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
syntax.
d. Can contain static variables unlike nonstatic inner
classes.
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.
Thanks
Milind
ravi chan
Greenhorn

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
Sheriff

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
Greenhorn

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

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

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
Hi,
One more point You cannot declare locale Inner class as a static. And Locale Inner class will not have any static members.
Regards
Satish
Milind Mahajan
Ranch Hand

Joined: Oct 23, 2000
Posts: 77
Hi,
You both are right Bin and Satish.
Sorry for the error.
Thanks
Milind
 
Don't get me started about those stupid light bulbs.
 
subject: Urgent on static