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


Please Help Members By Posting Answers For Below Questions

What is a modular application? What does module-relative mean?

538


Write a program to show synchronization?

689


Explain about RMI Architecture?

608


what is the use of State Factories?

1905


What are callback interfaces?

591






Define aop(assepct oriented programing)?

630


How to determine SGA site?

1906


What modifiers may be used with an inner class that is a member of an outer class?

569


Java is fully object oriented languages or not?

536


Can I import same package/class twice? Will the jvm load the package twice at runtime?

643


What event results from the clicking of a button?

691


How will you pass parameters in RMI? Why do you serialize?

686


What is Remote Server?

1682


What is the purpose of the wait(), notify(), and notifyall() methods?

566


What are the call back methods in entity bean?

557