Srinivas Katta wrote:It is possibl if we implement the line of code you have given, but that is not included in Original Source. in that Case how Line 9 will not give any compiler Error
But that's not the point. The compiler will only give an error if that cast cannot
possibly work. The compiler doesn't try to look at the previous lines and work out whether it will work - it looks at the types and works out whether it could.
Add my class E, and add the line
a = new E(); just before line 9, and the cast will be successful. And because it
could be successful, the compiler will allow it (and you'll get a run-time exception when it doesn't work).