File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overriding static methods 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 "Overriding static methods" Watch "Overriding static methods" New topic

Overriding static methods

Divya Dronamraju

Joined: Jan 07, 2008
Posts: 5
class sup
static void method(){System.out.println("Super");} // 1

class test extends sup
public static void main(String args[]) {}
static void method(){System.out.println("test");}

Is this an example of overriding? I thought static methods cannot be overridden...they can only be hidden... This concept is not clear to me. Can someone help me understand this?

vijaya saradhi
Ranch Hand

Joined: Dec 31, 2007
Posts: 32
Hi Divya.

First of all static methods belong to class.And they are not per each and evry object, ie not per instance of a class.So overriding can be done only on
non static member functions (instance methods only).

Since static members are part of a class nt seperate for each and evry individual objects of a class, this overriding concept doesn't apply to them.

even though static methods are inherited, they cannt be invoked dynamically using parent class reference(ie no dynamic binding since static)

for eg:
note even though the object is of type B the static function of the
type A (base) is called

So they are hidden in subclass.
marc weber

Joined: Aug 31, 2004
Posts: 11343

Also see Overriding vs. Hiding.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: Overriding static methods
jQuery in Action, 3rd edition