The following piece of code creates a run time error at line 2. As we are casting from base to sub (going down the tree) we need a cast. Line 2 has a cast. However if I change line 1 to Base1 base = new Sub() it works. I think I am missing a fundamental understanding of casting.
class Base1 {}
class Sub extends Base1 {}
public class Orange {
public static void main(
String args[]) {
Base1 base = new Base1(); // 1
Sub sub = (Sub)base; // 2
}
}