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

Is there a guarantee of uniqueness for entity beans?

577


Is the ternary operator written x : y ? Z or x ? Y : z ?

643


What restrictions are placed on the location of a package statement within a source code file?

627


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

2164


What does module-relative mean?

585






What is clustering? What are the different algorithms used for clustering?

586


Which are the different segments of memory?

610


Why are some of the class and element names counter-intuitive?

581


What are the diff types of exception?

569


Name the class that is used to bind the server object with RMI Registry?

1703


Difference between loadclass and class.forname?

609


Can I import same package/class twice? Will the jvm load the package twice at runtime?

653


What is the difference between session and entity beans?

587


what are RemoteObjects?

2266


cud u help me ... i am struggling with this question... to find all the subsets of a given set for ex.... a,,b,c shud give all the subsets.... i gt the program in c bt nt able to get it in java..... help needed ..

1745