• 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

Static modifier..

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
True/False?
Static can be applied to : instance variables, methods, code Segments and classes.
Thanks.
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Cathy Song:
Hi,
True/False?
Static can be applied to : instance variables, methods, code Segments and classes.
Thanks.


Looks a bit ambiguous to me. Yet another example of confusing wording.
:roll:
If a variable is already an instance variable, applying static modifier will make it a class variable. A top level class cannot be static, but a top level nested class can.
I haven't encountered any ambiguously worded questions like this one on the exam.
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cathy and Vad
The wording may be a bit ambiguous. I guess word instance variable is specified to specify that not all variables can be marked static. Though I guess it could have been done with just variables. The same applies for classes. Though not all classes can have static modifier but classes(some) may still have have the static modifier.
[ November 16, 2003: Message edited by: Anupam Sinha ]
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think if you take out the word instance (I agree with Vad on this), there's nothing else wrong with the statement:
Static can be applied to : variables, methods, code Segments and classes.
It can be applied to:
1. Variables: Yes (static variables)
2. Methods: Yes (static methods)
3. Code Segments: Yes (Static Initializers blocks)
4. Classes: Yes (Top level nested classes)
Cheers
Harwinder
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it is not confusting enough. sometimes you see static elements even without static keyword: all the interfaces variables are inherently static.
[ November 17, 2003: Message edited by: Tom Tang ]
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A 'static class' is an inner class which is a static member variable of the outer class.
Class Outer
{
static class StaticInner{};
}
In the above example, class StaticInner() is a static member variable .
So the answer is instance variables, methods, code Segments .
Any thoughts?
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
StaticInner class is not a static member variable. Rather, it's a member class.


Member class declarations (�8.5) describe nested classes that are members of
the surrounding class. Member classes may be static, in which case they have
no access to the instance variables of the surrounding class; or they may be inner classes (�8.1.2).
Member interface declarations (�8.5) describe nested interfaces that are members of the surrounding class.

 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is true. I don't see anything particularly ambiguous in the question. It might be a little confusing but I think Vad showed that if you think it out that you get the correct answer.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic