Derived Type Casting

1. 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 Manager1 { public static void main(String[] args) { // Object class is Super Class Of all Classes Object obj = new Object(); A a1 = new A(); B b1 = new B(); C c1 = new C(); D d1 = new D(); System.out.println("Done"); } }

2. 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 Manager2 { public static void main(String[] args) { Object obj = null; A a1 = null; B b1 = null; C c1 = null; D d1 = null; obj = new Object(); a1 = new A(); b1 = new B(); c1 = new C(); d1 = new D(); System.out.println("Done"); } }

3. 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 Manager5 { public static void main(String[] Args) { A a1 = new B(); B b1 = new C(); C c1 = new D(); Object obj = new A(); System.out.println("Done"); } }

4. 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 Manager6 { public static void main(String[] Args) { A a1 = new C(); Object obj = new D(); B b1 = new C(); C c1 = new D(); System.out.println("Done"); } }

5. 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 Manager8 { static void test(A a1) { System.out.println("test(A)"); } public static void main(String[] Args) { test(new B()); test(new C()); test(new D()); B b1 = new B(); test(b1); D d1 = new D(); test(d1); System.out.println("Done"); } }

Page....