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 is the immediate superclass of the applet class?
Which textcomponent method is used to set a textcomponent to the read-only state?
Which class is the immediate superclass of the menucomponent class?
Why a component architecture for the java platform?
Explain what is orm?
What you mean by COM and DCOM?
What is bean? Where can it be used?
What are the sequence of steps to write pub or sub model kind of application?
What are the different class loaders used by jvm?
What is a class loader?
What is ripple effect?
What are the different methods of identifying an object?
What is a tasks priority and how is it used in scheduling?
what are memory considerations of jsp compares to other web components?
Is the ternary operator written x : y ? Z or x ? Y : z ?