Harpreet Singh janda wrote : This will not fail at runtime. Can you please provide the actual code?
You are right. I meant the following won't run.
Given this code.
This will compile fine but will throw a class cast exception during runtime.
But the following will compile fine
superClass reference is pointing to the SubClass object. So the line
Compile and runs fine.