can a static method be overridden

Answer Posted / nilesh more

Finally, remember that static methods can't be overridden!
This doesn't mean they can't be redefined in a subclass, but
redefining and overriding aren't the same thing.
Let's take a look at an example of a redefined (remember,
not overridden), staticmethod:

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







The above written material is from kathe Siera which clearly
says that "Static methods can't be overridden."
But you can only redefine them which is not as overriding.
For any further perfect explanation please refer kathe Ciera
book

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which class is the immediate superclass of the menucomponent class?

611


What is a class loader? What are the different class loaders used by jvm?

574


What are the benefits of detached objects?

577


Explain phantom read?

1730


Why use a datasource when you can directly specify a connection details? (in a J2EE application)

3437






How will you pass parameters in RMI? Why do you serialize?

683


Define prototype?

575


Can I map more than one table in a cmp?

585


Explain how will the struts know which action class to call when you submit a form?

515


What’s jboss cache in short?

582


Where we can write Rmi registry in the code, without having to write it at the command prompt?

2245


What are the call back methods in entity bean?

550


Explain the steps in details to load the server object dynamically?

4536


What is the difference between system.out ,system.err and system.in?

591


What is difference between object state and behavior?

569