class Animal
{
static void doStuff()
{
System.out.print("a ");
}
}
class Dog extends Animal
{
static void doStuff() //redefinition,not overridden
{
System.out.println("Dog");
}
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();
}
}
}
well the answer i got is "a a a" when i expected " a Dog a" where have i gone wrong
a[0].doStuff() becomes Animal.doStuff() which becomes 'a'
a[1].doStuff() becomes dog.doStuff() which becomes 'Dog'
a[2].doStuff() becomes Animal.doStuff() which becomes 'a'
this is my interpretation but evidently i have gone wrong but where ?