aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static" Watch "Static" New topic
Author

Static

Raj Devaraj
Ranch Hand

Joined: Jun 29, 2000
Posts: 44
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
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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.
Marcela Blei
Ranch Hand

Joined: Jun 28, 2000
Posts: 477
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.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.
Jason
Ranch Hand

Joined: Dec 06, 2000
Posts: 35
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

Joined: Dec 06, 2000
Posts: 35
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

Joined: Jun 28, 2000
Posts: 477
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
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static