Derived type Casting

6. Program ( Derived Type Casting )

//Find what it gives Compiletion Error / Compiletion Successfully / Output ?

class A { } class B extends A { } class C extends B { } class D extends C { } class Manager9 { static Object test() { D d1 = new D(); return d1; } public static void main(String[] Args) { Object obj = test(); System.out.println("Done"); } }

7. Program

//Find what it gives Compiletion Error / Compiletion Successfully / Output ?

class A { } class B extends A { } class C extends B { } class D extends C { } class Manager10 { static C test() { D d1 = new D(); return d1; } public static void main(String[] Args) { A a1 = test(); System.out.println("Done"); } }

8. Program

//Find what it gives Compiletion Error / Compiletion Successfully / Output ?

class A { } class B extends A { } class C extends B { } class D extends C { } class Manager11 { static A test1(C c1) { return test2(c1); } static B test2(C c1) { return c1; } public static void main(String[] Args) { D d1 = new D(); Object obj = test1(d1); System.out.println("Done"); } }

9. Program

//Find what it gives Compiletion Error / Compiletion Successfully / Output ?

class A { } class B extends A { } class C extends B { } class D extends C { } class Manager12 { public static void main(String[] Args) { A a1 =(A) new B(); A a2 = new B(); C c1 = (C) new D(); C c2 = new D(); System.out.println("Done"); } }

10. Program

//Find what it gives Compiletion Error / Compiletion Successfully / Output ?

class A { } class B extends A { } class C extends B { } class D extends C { } class Manager13 { public static void main(String[] Args) { A a1 = new B(); B b1 = a1; System.out.println("done"); } }

Page....