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
What value does readline() return when it has reached the end of a file?
What is the relationship between local interfaces and container-managed relationships?
How to implement RMI in Java?
What restrictions are placed on the location of a package statement within a source code file?
What is a tasks priority and how is it used in scheduling?
the same information whether it will connect to the database or it will be used previous information?
What is an abstract method?
What is TL and its use?
What is ioc concept?
What are the purpose of introspection?
Can you control when passivation occurs?
What is the difference between a static and a non-static inner class?
What is the difference between the font and fontmetrics classes?
What are the types of scaling?
What modifiers may be used with an interface declaration?