Mezan Shareef wrote:
Arhaan Singhania wrote:Hi Pinki,
The methods are basically overloaded and choice of which overloaded method to call or the signature depends upon
reference type and signature. If you see the method is taking Mammal reference so it is calling the Mammal eating
Hay. I guess this is the correct answer.
Arhaan
Hi Arhaan
I dont see methods overloaded, eat method have only one parameter, they are overridden. but, i think, h is of type mamal, so mamal code is excuted. I did not execute the code though, just guessing.
hi mezan i think that arhaan is right... if you read katy and bert book about rule of overriding, they said that :"The argument list must exactly match that of the overridden method. If they
don't match, you can end up with an overloaded method you didn't intend"
the problem here is this : Mammel is a parent of Cattle and cattle is the parent of Horse
so Horse inherit all eat() method from Mammel and Cattle
Cattle inherit eat() method from Mammel
so if you call the eat method from Horse object and pass a Cattle or Mammel reference , it will call the Cattle or Mammel eat method because Horse object inherit them.
regards.