File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding static methods" Watch "Overriding static methods" New topic
Author

Overriding static methods

Divya Dronamraju
Greenhorn

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?

Thanks!
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
Sheriff

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
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overriding static methods