• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Urgent on static

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good Job Milind. If I am right you can add :
Cannot declare a static variable inside an instance method
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow... What a great job, Milind!
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great job!!!
 
Milind Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks a lot all of you.
Milind
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You both are right Bin and Satish.
Sorry for the error.
Thanks
Milind
 
reply
    Bookmark Topic Watch Topic
  • New Topic