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
Difference between hashmap and hashtable?
What restrictions are placed on the location of a package statement within a source code file?
Are enterprise beans allowed to use thread.sleep()?
What are the types of scaling?
Do you think that java should have had pointers?
whats is mean by connectionpooling
what are RemoteObjects?
Explain what is orm?
what is an isolation level?
What is bean? Where can it be used?
whats is mean by tiles in struts
What are the benefits of detached objects?
Is it possible to stop the execution of a method before completion in a sessionbean?
Is “abc” a primitive value?
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