can a static method be overridden

Answer Posted / vinay

Making things more clear, how static and non-static method
behaves
public class Super
{

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

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

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

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


Result:
superclass static
subclass nonstatic
subclass static
subclass nonstatic

Note: The first output is not "subclass static" as with non
static methods.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which javutil classes and interfaces support event handling?

581


What is the difference between the string and stringbuffer classes?

543


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

1812


What is the argument type of a programs main() method?

561


What modifiers may be used with an interface declaration?

558






Why does the tag url-encode javascript and mailto links?

578


What are the different algorithms used for clustering?

548


Is jvm a overhead?

623


What is the difference between a static and a non-static inner class?

596


Why is string immutable in java?

577


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

597


How primary key is implemented in Oracle?

1914


How to pass parameters in RMI?

1688


Explain about local interfaces.

585


What is the relation between the infobus and rmi?

556