Gursewak Singh wrote:i have a code:
subClass obj=new superClass();
obj.eat();
Here eat() method is overridden in the sub class.
as we know that in case of method overriding Object type(not reference type determine) ,determine which overridden method is used at run time.so in this case this code should work according to statement.
But this show compilation error for incompatible type.
so i want to know ,why?
To make it a little easier to spot consider this code:
....and consider this code:
Explanations are in the comments. let me know if you have more questions.