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
Why is string immutable in java?
What is the relationship between local interfaces and container-managed relationships?
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
Define the remote object implementation?
What are the call back methods in entity bean?
What are transaction attributes?
What modifiers may be used with an inner class that is a member of an outer class?
What must a class do to implement an interface?
Difference between swing and awt?
How to determine SGA site?
What is table mutation and how do you avoid it?
How many times may an objects finalize() method be invoked by the garbage collector?
Is the ternary operator written x : y ? Z or x ? Y : z ?
Why use a datasource when you can directly specify a connection details?
Why use a datasource when you can directly specify a connection details? (in a J2EE application)