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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "static methods" Watch "static methods" New topic
Author

static methods

Chris Cleverley
Greenhorn

Joined: Mar 09, 2007
Posts: 22
a static method cannot be overriden to be non-static but is the reverse true i.e, can a non-static method be overriden to be static ?
After running a sample code I get a compiler error.
Chris
Aru
Ranch Hand

Joined: Jul 20, 2000
Posts: 112
Hi Chris,
Keep in mind that - When overiding a method, it can't be made more "PRIVATE" than the parent method.
Aruna
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Chris,
Static methods are attached to classes instead of instances. Hence they don't exhibit polymorphism and the term "override" does not fit into the semantics of static methods.
When you re-declare a parent non-static method as a static method in the subclass, you will be hiding the instance method in the parent class which is illegal. You will get the following compilation error
StaticOverrideDemo.java:8: The static method void doSomething() declared in clas
s Sub cannot hide the instance method of the same signature declared in class Ba
se. It is illegal to hide an instance method.

Hope this helps,
Ajith


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Chris Cleverley
Greenhorn

Joined: Mar 09, 2007
Posts: 22
I got it. Thanks you all.
Chris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static methods
 
Similar Threads
Static methods
Confusion!
Overridding Static Methods
Why can't a statice method can be overriden to a non-static method?
Overriding static / non static methods