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 synchronization and why is it important?
Will the general public have access to the infobus apis?
Whats new with the stop(), suspend() and resume() methods in jdk 1.2?
What restrictions are placed on the location of a package statement within a source code file?
What is the relationship between an event-listener interface and an event-adapter class?
Is the infobus client side only?
What is a tasks priority and how is it used in scheduling?
What are the types of scaling?
Do I have to use jsps with my application?
which type of objects reference will be given to client?
What is the purpose of the finally clause of a try-catch-finally statement?
What are various types of class loaders used by jvm?
What is scalable, portability in the view of J2EE?
Why use a datasource when you can directly specify a connection details?
If your ui seems to freeze periodically, what might be a likely reason?