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
What are the different methods of identifying an object?
Which class is the immediate superclass of the menucomponent class?
What is the difference between RMI and Corba?
What is a sessionfactory? Is it a thread-safe object?
what is a non-repeatable read?
Why won’t the jvm terminate when I close all the application windows?
What are the diff types of exception?
Why is string immutable in java?
What do you need to set-up a cluster with jboss?
Why use a datasource when you can directly specify a connection details? (in a J2EE application)
How can I scroll through list of pages like the search results in google?
Explain how will the struts know which action class to call when you submit a form?
When a thread blocks on i/o, what state does it enter?
Have you used threads in Servelet?
What are the different types of exception?