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 externizable interface?
How primary key is implemented in Oracle?
In RMI, inorder to sent the stub reference to the client, is we have to load the server object first into the memory or can we directly sent reference to the client?
Is the ternary operator written x : y ? Z or x ? Y : z ?
What is the relationship between the canvas class and the graphics class?
What does module-relative mean?
Why is string immutable in java?
what is handle?
Should synchronization primitives be used on bean methods?
In inglish: How to convert jar to exe files? Em português: Como converter arquivos .jar para .exe?
Difference between new operator and class.forname().newinstance()?
What is colon_pkg_prefixes and what is its use?
Can constructors be synchronized in java?
int x=5,i=1,y=0; while(i<=5) { y=x++ + ++x; i=i+2; } System.out.println(x); System.out.println(y); System.out.println(i); How to solve this? Please explain!
When a thread blocks on i/o?