Forums Register Login

Static clarifications required

+Pie Number of slices to send: Send
Which of the follwing 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 & private.
D. a static reference cannot be made through non static method or code block.
E. abstract & static both can be applied together to a method.
Could somebody get me the correct answers with detail explanations
Thanks
+Pie Number of slices to send: Send
Hi Suren.Going through the options...
A.static can be applied to : instance variables, methods, code Segments and classes - TRUE.Well,static can be applied to VARIABLES and not instance variables as u have written.Instance variables are those which belong to a particular Object.The rest are all true.
B. a static method cannot be overridden.- TRUE.Static methods are RE-DEFINED in the subclass.
C. inner classes can be both static & private. - TRUE.
D. a static reference cannot be made through non static method or code block - FALSE.It is vice-versa , ie. a non-static variable cannot be accesed through a static method unless an object reference is present.
E. abstract & static both can be applied together to a method. -FALSE. It is not allowed by the compiler.This is because an abstract method is incomplete.It's definition is provided by the subclass.So if this method is made static,what will i do with that incomplete method ?
Since abstract methods are not allowed to be made static, you will require an object of the class to which that abstract method belongs.And that would be impossible,since u cannot instantiate an abstract class.Thus the only way out is to extend that class and override the abstract method.
Sorry if i have been too articulate in my explanations.



------------------
Come on in !! Drinks are on the house in the Big Moose Saloon !!
[This message has been edited by Udayan Naik (edited November 03, 2000).]
+Pie Number of slices to send: Send
Thanks
Great explanations in simple terms ...
+Pie Number of slices to send: Send
Hai,
I think staic methods cann't be overridden to be non-static.
If you override that to be static ,it's ok.
Anyone correct me if i am wrong.
bye
+Pie Number of slices to send: Send
static methods cannot be overridden in the subclass
STATIC MEMBERS BELONG TO THE CLASS IN WHICH IT IS DECLARED.....
Yu can override only if the members r inherited, and if static members belong to the superclass, it is not inherited by the subclass, Hence they cannot be overridden......
hope it helps
Yeah. What he said. Totally. Wait. What? Sorry, I was looking at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 742 times.
Similar Threads
Static reference
Doubt in Overriding Static Method....?
Q from valiveru
Static
static modifier
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 03:35:27.