posted 19 years ago
Hi,
This is an example of overloading.
Lets go through the code
c.eat calls the eat method in Cattle class.Now the Cattle class has two overloaded methods.
void eat(Mammal m) and void eat(Cattle c) as Cattle extends Mammal class
Now comes the trickest part...
The compiler looks at the passed argument's reference type(note it doesn't care about the object the reference actually contains).The argument's reference type is Mammal.Hence the void eat(Mammal m) method is called.
Hence the output is:
Mammal eats food.
-vinu.
[ May 09, 2005: Message edited by: vinuharan haran ]