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 onl

Is This Answer Correct ?    9 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Difference between hashmap and hashtable?

598


What restrictions are placed on the location of a package statement within a source code file?

607


Are enterprise beans allowed to use thread.sleep()?

639


What are the types of scaling?

545


Do you think that java should have had pointers?

590






whats is mean by connectionpooling

1558


what are RemoteObjects?

2249


Explain what is orm?

666


what is an isolation level?

2205


What is bean? Where can it be used?

573


whats is mean by tiles in struts

1611


What are the benefits of detached objects?

577


Is it possible to stop the execution of a method before completion in a sessionbean?

588


Is “abc” a primitive value?

609


A user of a web application sees a jsessionid argument in the URL whenever a resource is accessed. What does this mean? a. The form must have the field jsessionid b. URL rewriting is used as the session method c. Cookies are used for managing sessions

1805