package inheritance; public class Main { public static void main(String[] args) { BaseClass [] x= { new BaseClass(), new Derived() }; x[0].method1(); // Base method1 x[1].method1(); // Derived Method1 // x[0].method2(); // Compile Time Error // ((Derived)x[0]).method2(); // Class Cast Exception // x[1].method2(); // Compile Time Error ((Derived)x[1]).method2(); ((Derived)x[1]).method3(); System.out.println(x[0].x+" "+x[1].x+" "+((Derived)x[1]).y); // 0 0 2 System.out.println(x[0].x+" "+((Derived)x[1]).x); // 0 1 System.out.println(x[0].x()+" "+x[1].x()+" "+((Derived)x[1]).y); // 0 1 2 System.out.println(x[0].z+" "+x[1].z+" "+((Derived)x[1]).z); // 0 0 3.0 } }