• 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

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following is true about static modifier?
A. static can be applied to : instance variables, methods, code segments and classes.
B. a static method cannot be overridden.
C. inner classes can be both static and private.
D. a static reference cannot be made through non static method or code block.
E. abstract and static both can be applied together to a method.
The correct answers given are B, C & D.
I don't agree with option B. A static method can be overridden. It may be hidden, but still the code compiles and can be accessed as DerivedClass.method().
Also why not option A. My selections are A, C & D. Any help is appreciated.

Thanks
Raj
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Raj Devaraj:
Which of the following is true about static modifier?
A. static can be applied to : instance variables, methods, code segments and classes.
B. a static method cannot be overridden.
C. inner classes can be both static and private.
D. a static reference cannot be made through non static method or code block.
E. abstract and static both can be applied together to a method.
The correct answers given are B, C & D.
I don't agree with option B. A static method can be overridden. It may be hidden, but still the code compiles and can be accessed as DerivedClass.method().
Also why not option A. My selections are A, C & D. Any help is appreciated.

Thanks
Raj


-------------------------------------
Hi,
A) is a bit sneaky one. caution with wording: static can be applied to : INSTANCE variables, methods , blah blah...
B) I agree with you, static method can be overriden with another static method.
C)correct, inner classes is just like any other class fields.
D)IMHO, this one is wrong one. nonstatic mehtod and code block can freely make reference to static references.
E)absolutely wrong. abstract can be co-existent with final, static, synchronized and native keywords.
Anyone has a definitive answer to B.
 
Ranch Hand
Posts: 477
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't agree with option B too. Please follow the rules and post this question (with the source where you get it) in the Mock errata forum.
Thanks.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it's not an error. "Overridden" and "hidden" are two different things, though they are very similar. If a method is static, it can be hidden; it cannot be overridden. This is precisely defined in the Java Language Specification.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking back at the original question though, D is certainly incorrect.
Lessee...
A - false because it mentions INSTANCE variables, which by definition are not static.
B - false as discussed above.
C - true. (Well technically it's false since static member classes are not truly inner classes according to the Inner Classes Specification or the JLS 2nd edition, but since this fact is widely disregarded even by Sun's exam authors, we'll ignore it.)
D - false. Try it; it's easy to do.
E - true. Try it; there will be a compiler error. Hint - this ties in to B. An abstract method must be overridden to be used; a static method cannot be overridden. Therefore a static abstract method could never possibly be used for anything, and so they made it illegal.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jim Yingst:
Looking back at the original question though, D is certainly incorrect.
Lessee...
A - false because it mentions INSTANCE variables, which by definition are not static.
B - false as discussed above.
C - true. (Well technically it's false since static member classes are not truly inner classes according to the Inner Classes Specification or the JLS 2nd edition, but since this fact is widely disregarded even by Sun's exam authors, we'll ignore it.)
D - false. Try it; it's easy to do.
E - true. Try it; there will be a compiler error. Hint - this ties in to B. An abstract method must be overridden to be used; a static method cannot be overridden. Therefore a static abstract method could never possibly be used for anything, and so they made it illegal.


-----------------------
Hi, Jim;
Some doubts about your comments above.
Here I guess you wanna to say B is true, i.e. a static method can not be overriden according to JLS, right?
C. From the SCJP2 exam's point of view, when it says an inner class, should I take it as an nonstatic inner class or an inner class including static and nonstatic both? I hope there won't be language ambiguity.
D. I would also assume what you mean is that D is false.
Correct me if I am wrong.
 
Jason
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Jim;
I just came back from another posting, it seems like that you have referred to Carl's note, but that link does not work.
Can you give me the right one.
TIA.
 
Marcela Blei
Ranch Hand
Posts: 477
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jim Yingst:
B - false as discussed above.


Hi Jim!
Look that I suggest to put this question in the errata forum cause the given right answers for this questions include the b option.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jason- right about B; I meant to say that it is TRUE as discussed above. As for C, from the exam point of view, just pretend "inner" classes includes all forms of nested classes, including static nested classes. And for D, I mean that D is false, as I said (correctly this time).
Marcela- it would be an errata, but so far no one has said where it came from.
 
reply
    Bookmark Topic Watch Topic
  • New Topic