First, this example is not overloading, it's overridding...
Ankur kothari wrote:
now here at compile time wont the parent string be selected based on the Parent reference? why is the output then "child"
Yes, the string is referenced at compile time. So, the Parent class' say() method will reference the Parent string. And the Child class' say() method will reference the Child string... both determined at compile time.
In your main method, you are not referencing any string. You are calling the say() method, which is resolved at runtime.
Henry