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 the argument type of a programs main() method?
What is a class loader?
What is message driven beam?
Why doesn’t the focus feature on the tag work in every circumstance?
Explain about RMI Architecture?
What is table mutation and how do you avoid it?
which type of objects reference will be given to client?
What’s jboss jbpm?
Which are the different segments of memory?
Explain the advantages and disadvantages of detached objects.
Are there books about seam?
How are the elements of a borderlayout organized?
What is the purpose of the finally clause of a try-catch-finally statement?
How task's priority is used in scheduling?
hi friends, i have done my BE(CSE)at 2011 then i have joined one company before they asked me 50k so i paid but now they telling no project here so we r going to close like that so now i need any job i have good knowledge in core java and j2ee(jsp,servlet,jdbc) so if u know any job pl help me