class Animal{
public void eat(){
System.out.println("I m in Animal");
}
}
class Horse extends Animal{
public void eat(){
System.out.println(" I m in Horse");
}
}
public class first{
public static void main(
String[] args){
Animal a=new Animal();
Animal b=new Horse();
a.eat();
b.eat();
}
}
Dear Sir in the prciding code i have taken two refrence a and b of type Animal. In b i m assigning the object of type Horse that's why b.eat() is calling the horse version of eat.
But on the other hand it has been written in Book K and B on page 101 that "The compiler looks only the refrence type , not the instance type" then if this then b is a refrence type of Animal then why it is calling the Horse version of eat()?
withe Regard
Arun kumar maalik