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


Please Help Members By Posting Answers For Below Questions

What is the argument type of a programs main() method?

553


What is a class loader?

576


What is message driven beam?

571


Why doesn’t the focus feature on the tag work in every circumstance?

555


Explain about RMI Architecture?

601






What is table mutation and how do you avoid it?

1903


which type of objects reference will be given to client?

2018


What’s jboss jbpm?

570


Which are the different segments of memory?

583


Explain the advantages and disadvantages of detached objects.

567


Are there books about seam?

621


How are the elements of a borderlayout organized?

587


What is the purpose of the finally clause of a try-catch-finally statement?

547


How task's priority is used in scheduling?

1771


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

1770