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 is the relationship between the canvas class and the graphics class?
what is Activation Instantinator?
What are the different methods of identifying an object?
What do you know about seam?
What is local interface. How values will be passed?
How to determine SGA site?
Can I use javascript to submit a form?
When is the best time to validate input?
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
What is permgen or permanent generation?
Explain about thread synchronization inside a monitor?
What are the different class loaders used by jvm?
What restrictions are placed on the values of each case of a switch statement?
Write a program to show synchronization?
Is there a guarantee of uniqueness for entity beans?