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
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
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.
Originally posted by Jim Yingst:
B - false as discussed above.
"I'm not back." - Bill Harding, Twister