Answer Posted / ashish
Hi All,
static method can never be overridden, to clear your doubt
I have written the following two java files
Base.java -->
public class Base {
public static void method(){
System.out.println("base");
}
}
Child.java -->
public class Child extends Base {
public static void method(){
System.out.println("Child");
}
public static void main(String[] args) {
Base baseObj = new Child();
baseObj.method();
baseObj = new Base();
baseObj.method();
}
}
The class file for Child.java is:
public class Child extends Base
{
public Child()
{
}
public static void method()
{
System.out.println("Child");
}
public static void main(String args[])
{
Base baseObj = new Child();
Base.method();
baseObj = new Base();
Base.method();
}
}
As you can see in case of static method object got replaced
by Class Name(here Base).
And i believe you all are aware of fact that overridden is
the case when resolution is done at Runtime.
But since in our case calling is decided at compile time,
so there is no case of overridden.
Do let me know, if you have further query
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
What must a class do to implement an interface?
Brief description about local interfaces?
What are the different methods of identifying an object?
difference between ejb,struts,hibernate,spring and jsp
What is ioc concept?
What are the purpose of introspection?
What are the call back methods in entity bean?
Do I have to use jsps with my application?
How to implement RMI in Java?
What is in-memory replication?
Is the infobus client side only?
How are the elements of a cardlayout organized?
What you mean by COM and DCOM?
whats is mean by tiles in struts
What is a modular application? What does module-relative mean?