For the following question:
interface I1 {} interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Orange {
public static void main(
String args[]) {
Base base = new Base();
I1 i1 = base; // 1
Sub sub = (Sub)base; // 2
}}
Answer:Run-time error at line 2
Doubts:
1. why error @ runtime and not compile time?
2. is this always the case that whenever we downcast a parent class we will get runtime error?
Please help,
regards,
gitesh