can a static method be overridden
Answer Posted / konthoujan 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 .
| Is This Answer Correct ? | 5 Yes | 5 No |
Post New Answer View All Answers
What are the types of scaling?
Can we sent objects using Sockets?
Which javutil classes and interfaces support event handling?
What you mean by COM and DCOM?
What is the purpose of the finally clause of a try-catch-finally statement?
How to implement RMI in Java?
What is Remote Server?
How to pass parameters in RMI?
What are various types of class loaders used by jvm?
How to deploy Jar, War files in J2EE?
What is the difference between long.class and long.type?
What is the purpose of the notify() method?
Why does the tag url-encode javascript and mailto links?
Why do I get a duplicate name error when loading a jar file?
Why won’t the jvm terminate when I close all the application windows?