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
What is a clone?
cud u help me ... i am struggling with this question... to find all the subsets of a given set for ex.... a,,b,c shud give all the subsets.... i gt the program in c bt nt able to get it in java..... help needed ..
What is the map interface?
Where can I find seam examples and documentation?
What is the purpose of the wait() method?
how i secure my site with the https protocol.what are the steps?
Define aop(assepct oriented programing)?
Explain the difference between object state and behavior?
What must a class do to implement an interface?
What are the steps to write p-to-p model application?
Explain the steps in details to load the server object dynamically?
How can I scroll through list of pages like the search results in google?
Can I map more than one table in a cmp?
What are the different types of exception?
What are the pros and cons of detached objects?