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 are transaction attributes?
What do you mean by Socket Programming?
Do you think that java should have had pointers?
What are JTA/JTS and how they used by client?
Where we can write Rmi registry in the code, without having to write it at the command prompt?
What are callback interfaces?
What modifiers may be used with an interface declaration?
Can you give me a simple example of using the requiredif validator rule?
Should synchronization primitives be used on bean methods?
In our urls and in the text of the buttons we have comma. Its causing an error. Is there a way to change the delimiting character for the menu arguments?
What is a class loader? What are the different class loaders used by jvm?
How to pass parameters in RMI?
Which textcomponent method is used to set a textcomponent to the read-only state?
Name three component subclasses that support painting?
What is scalable, portability in the view of J2EE?