Way is not an X.so why compiler allows.Is it because explicit casts says to compiler don`t worry I know what i am doing .
Even it is the case why it doen`t result in runtime exception
The reason that the compilers allows it, is because, in theory, it is possible to subclass from the Way class *and* implement the X interface. This means that is is possible to have an instance that is both IS-A Way and IS-A X. And since, at compile time, the compiler can't tell if that is the case (or more correctly, nothing in the specification that allows the compiler to confirm the case), the cast is allowed.