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
How to deploy Jar, War files in J2EE?
What is the difference between system.out ,system.err and system.in?
Which class is the immediate superclass of the menucomponent class?
Brief description about local interfaces?
What is prototype?
Explain the steps in details to load the server object dynamically?
whats is mean by connectionpooling
What is glasgow?
Why doesn’t the focus feature on the tag work in every circumstance?
What are the pros and cons of detached objects?
Difference between hashmap and hashtable?
What is the relation between the infobus and rmi?
Explain about RMI Architecture?
Which component handles cluster communication in jboss?
Explain ioc concept?