I know the concept of polymorphism and can get the idea, but I yet found an answer to why both in Java and C# the compiler allows you cast some class into interface, although the class doesn’t implement the interface at all.
class MyStupidClass{
}
interface Ix {
void doSomehting();
}
//inside some method:
Ix a = (Ix)new MyStupidClass();//compiled and will throw runtime error.
It will be crash on the run time. Both in Java and C#.
I can understand the downcasting concept which the child can sometimes be a type of the parent, but not this interface casting.