can a static method be overridden
Answer Posted / koushik1121
class Animal
{
static void meth1()
{
System.out.println("THIS IS A METHOD");
}
}
class Dog extends Animal
{
static void meth1()
{
System.out.println("THIS IS An overriding METHOD");
}
}
public class Test2 extends Dog
{
public static void main(String args[])
{
((Animal)new Dog()).meth1();
}
}
if static method can be overriden output of the above
program should be
THIS IS An overriding METHOD
because overriden depends on object type not reference type
but real output is
THIS IS A METHOD
depending upon the reference Animal for Dog object.
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Do we need to override service() method
How database connectivity in XML is achieved?
Name three subclasses of the component class?
What is the purpose of the notifyall() method?
what is a non-repeatable read?
What is message driven beam?
What is a clone?
Why doesn’t the focus feature on the tag work in every circumstance?
What is Remote Server?
What is the difference between static and non-static with examples?
Java is fully object oriented languages or not?
Is a class a subclass of itself?
Which containers use a border layout as their default layout?
When a thread blocks on i/o, what state does it enter?
How task's priority is used in scheduling?