Casting correctness can only be checked at runtime. So in your example, even though it might be obvious to you, for the program it won't know it's incorrect until it's actually running and attempts to cast the variable a as the interface G. At this point it will throw a ClassCastException.