aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static clarifications required Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static clarifications required" Watch "Static clarifications required" New topic
Author

Static clarifications required

Suren Babu
Greenhorn

Joined: Oct 23, 2000
Posts: 27
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
Udayan Naik
Ranch Hand

Joined: Oct 18, 2000
Posts: 135
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).]


Udayan Naik<BR>Sun Certified Programmer for the Java 2 Platform
Suren Babu
Greenhorn

Joined: Oct 23, 2000
Posts: 27
Thanks
Great explanations in simple terms ...
Ram Jonnalagadda
Greenhorn

Joined: Nov 05, 2000
Posts: 6
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
SHALINI PATEL
Ranch Hand

Joined: Oct 31, 2000
Posts: 41
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static clarifications required