This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "static methods" Watch "static methods" New topic

static methods

Chris Cleverley

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.
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.
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
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 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,

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

Joined: Mar 09, 2007
Posts: 22
I got it. Thanks you all.
I agree. Here's the link:
subject: static methods
It's not a secret anymore!