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
Difference between swing and awt?
What is difference between object state and behavior?
What event results from the clicking of a button?
Can you give me a simple example of using the requiredif validator rule?
What is the RMI and Socket?
What is in-memory replication?
Is there a guarantee of uniqueness for entity beans?
What are the sequence of steps to write pub or sub model kind of application?
What is meant by method chaining?
What is the difference between ear, jar and war file?
Explain RMI Architecture?
Why use a datasource when you can directly specify a connection details?
What is the difference between the font and fontmetrics classes?
How to determine SGA site?
What class is used to create Server side object ?