Dear Mamatha,
As per your suggestion, I am including the question also. The code given below is with refernce to the explanation of the fact that "static methods can not be overridden". However, we are always free to redefine the method as done in the following code. Now I again repeat my question : What is the difference between overriding and redefining a method. From the code it seems as if we are doing overriding. Please elaborate method overriding & redefining.
Please note that the code given below works pretty fine and produces an output "aaa" when run.
class Animal
{
static void doStuff()
{
System.out.print("a");
}
}
class Dog extends Animal
{
static void doStuff()
{
System.out.print("d");// it's a redefinition
// not a override
}
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();
}
}