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
Which characters may be used as the second character of an identifier, but not as the first character of an identifier?
difference between ejb,struts,hibernate,spring and jsp
What are the oops concept?
Is there a guarantee of uniqueness for entity beans?
Difference between loadclass and class.forname?
How task's priority is used in scheduling?
What is a class loader?
What is a tasks priority and how is it used in scheduling?
What is the map interface?
What is meant by method chaining?
Why is actionform a base class rather than an interface?
If we opened Windows Internet Explorer 4 times, does it starts 4 processes or 4 threads?
What are the benefits of detached objects?
Explain about thread synchronization inside a monitor?
Difference between DurableSubscription and non- DurableSubscription?