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 textcomponent method is used to set a textcomponent to the read-only state?
what is a portable component?
What is the highest-level event class of the event-delegation model?
Is “abc” a primitive value?
What are callback interfaces?
Is a class a subclass of itself?
Difference between DurableSubscription and non- DurableSubscription?
What modifiers may be used with an interface declaration?
Describe, in general, how java's garbage collector works?
What is glasgow?
What is abstract schema?
When a thread blocks on i/o, what state does it enter?
Where we can write Rmi registry in the code, without having to write it at the command prompt?
What is an abstract method?
Do I have to use jsps with my application?