can a static method be overridden
Answer Posted / konthoujam dhanabir singh
static method cannot be overriden to non-static.so static
method can be overriden to static.
the above example is true in static way
e.g.
class Animal {
static void doStuff() {
System.out.print("a ");
}
}
class Dog extends Animal {
static void dostuff() { // it's a redefinition,
// not an override
System.out.print("d ");
}
public static void main(String [] args) {
Animal [] a = {new Animal(), new Dog(), new Animal()};
for(int x = 0; x < a.length; x++)
a[x].doStuff(); // invoke the static method
}
}
Running this code produces the output:
a a a
Some case:
in the subclass Dog, if the method dostuff() is not
static,it will be compile time error in the above code
block .
So a static method cannot be overriden
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Explain RMI Architecture?
What is the argument type of a programs main() method?
Is it possible to stop the execution of a method before completion in a sessionbean?
How is a java object message delivered to a non-java client?
What are the services in RMI ?
What value does read() return when it has reached the end of a file?
what is an isolation level?
Describe, in general, how java's garbage collector works?
Explain about local interfaces.
What method is invoked to cause an object to begin executing as a separate thread?
what is meant by JRMP?
What is permgen or permanent generation?
What is the purpose of the wait() method?
Why does the option tag render selected=selected instead of just selected?
To what value is a variable of the string type automatically initialized?