can a static method be overridden

Answer Posted / ramandeep

Yes you can override static methods..
see the following two classes :
public class Super
{
public static void main(String args[])
{

}

public static void m1()
{
System.out.println("superclass");
}
}


public class Sub extends Super
{
public static void main(String args[])
{
Super superWalaObj = new Sub();
superWalaObj.m1();

Sub subWalaObj = new Sub();
subWalaObj.m1();
}

public static void m1()
{
System.out.println("subclass");
}
}

Running this gives the following output :
superclass
subclass

Which explains the behaviour itself.

By overriding the static methods we are forcing them to
behave as non-static methods when used with object.
However, making a call directly to the staticy. method will
call the method belonging to that class only

Is This Answer Correct ?    7 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between session and entity beans?

571


Name the class that is used to bind the server object with RMI Registry?

1686


What is the purpose of the wait() method?

610


What is the relation between the infobus and rmi?

549


whats is mean by tiles in struts

1609






What classes of exceptions may be caught by a catch clause?

544


Which javutil classes and interfaces support event handling?

571


How can I avoid validating a form before data is entered?

543


What is difference between object state and behavior?

569


Explain about local interfaces.

573


Are there books about seam?

621


In RMI, inorder to sent the stub reference to the client, is we have to load the server object first into the memory or can we directly sent reference to the client?

1550


What is threadfactory?

604


What is clustering? What are the different algorithms used for clustering?

567


Describe, in general, how java's garbage collector works?

528