can a static method be overridden
Answer Posted / raghvendra
Look at the code and resule below and Interpret it
yourself .. :) .. it is pretty easy.
public class A {
public static void staticMethod(){
System.out.println("Static: I print from
A");
}
public void nonStaticMethod(){
System.out.println("Non Static: I print
from A");
}
}
public class B extends A{
public static void staticMethod(){
System.out.println("Static: I print from
B");
}
public void nonStaticMethod(){
System.out.println("Non Static: I print
from B");
}
}
public class Launcher {
public static void main(String[] args) {
A a = new A();
B b = new B();
A obj = new B();
System.out.println("obj instanceof A : " +
(obj instanceof A));
System.out.println("obj instanceof B : " +
(obj instanceof B));
a.staticMethod();
a.nonStaticMethod();
b.staticMethod();
b.nonStaticMethod();
obj.staticMethod();
obj.nonStaticMethod();
}
}
Consol Output:
obj instanceof A : true
obj instanceof B : true
Static: I print from A
Non Static: I print from A
Static: I print from B
Non Static: I print from B
Static: I print from A <--- See the difference here.
Non Static: I print from B <--- See the difference here.
Good luck!
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
what is handle?
What is re-entrant. Is session beans reentrant. Is entity beans reentrant?
How can I scroll through list of pages like the search results in google?
Can I map more than one table in a cmp?
wahts is mean by dynavalidatorform in struts/
Define aop(assepct oriented programing)?
What do you know about seam?
Which class is the immediate superclass of the menucomponent class?
When a thread blocks on i/o, what state does it enter?
What are various types of class loaders used by jvm?
Can we sent objects using Sockets?
Can I use javascript to submit a form?
What classes of exceptions may be caught by a catch clause?
Define prototype?
the same information whether it will connect to the database or it will be used previous information?