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

What is the purpose of the notify() method?

596


Do you think that java should have had pointers?

596


What is a modular application?

589


the same information whether it will connect to the database or it will be used previous information?

570


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

595






What is the difference between RMI registry and OS Agent?

628


when A client sent a request to the server to open facebook page and close the browser after this request .at that time the same user do login by using a different browser then that session id will exist or not for the same client??

1100


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

693


In inglish: How to convert jar to exe files? Em português: Como converter arquivos .jar para .exe?

2155


What is table mutation and how do you avoid it?

1915


What you mean by COM and DCOM?

613


what is Activation Instantinator?

1907


What value does readline() return when it has reached the end of a file?

589


How many times may an objects finalize() method be invoked by the garbage collector?

670


What is an abstract method?

590