can a static method be overridden
Answer Posted / karteek
Hi, Srinivas.....in the above program posted by Aswini...I
think main() method is overridden....right?.....then we can
say static methods can be overridden....
Eg:
class Parent
{
public static void myStaticMethod()
{
System.out.println("A");
}
public void myInstanceMethod()
{
System.out.println("B");
}
}
public class Child extends Parent
{
public static void myStaticMethod()
{
System.out.println("C");
}
public void myInstanceMethod()
{
System.out.println("D");
}
public static void main(String[] args)
{
Parent o1 = new Parent();
Child o3 = new Child();
Parent.myStaticMethod(); // A
Child.myStaticMethod(); // C
o1.myStaticMethod(); // A
o1.myInstanceMethod(); // B
o3.myStaticMethod(); // C
o3.myInstanceMethod(); // D
}
}
In the above program myStaticMethod() is
overridden.....which is a static method.....
| Is This Answer Correct ? | 10 Yes | 16 No |
Post New Answer View All Answers
What is the difference between long.class and long.type?
What is meant by method chaining?
Explain how will the struts know which action class to call when you submit a form?
Why are my checkboxes not being set from on to off?
What is the relation between the infobus and rmi?
What is the diffrence between a local-tx-datasource and a xa-datasource?
Difference between DurableSubscription and non- DurableSubscription?
Why a client should be multithreading? Explain.
What must a class do to implement an interface?
What is the difference between the session.update() method and the session.lock() method?
What are the pros and cons of detached objects?
Explain about local interfaces.
Explain the difference between object state and behavior?
Should synchronization primitives be used on bean methods?
wahts is mean by dynavalidatorform in struts/