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
Which are the different segments of memory?
What is meant by method chaining?
Describe activation process?
What is the diffrence between a local-tx-datasource and a xa-datasource? Can you use transactions in both?
What value does read() return when it has reached the end of a file?
What is local interface. How values will be passed?
What is colon_pkg_prefixes and what is its use?
what are the advantages of JTA over JTS?
What is the difference between a static and a non-static inner class?
What is the difference between session and entity beans?
Explain about local interfaces.
Where can I ask questions and make suggestions about seam?
What is permgen or permanent generation?
Java is fully object oriented languages or not?
int x=5,i=1,y=0; while(i<=5) { y=x++ + ++x; i=i+2; } System.out.println(x); System.out.println(y); System.out.println(i); How to solve this? Please explain!