Tuesday, April 26, 2005

Casting Continues....(Test ur Casting Skiils!!)

To make sure you understand everything presented in previous article, assume that the following two class definitions exist.

class B {
int x;
}

class D : B {
int x;
}


ES: Execute Successfully
CE: Compiler Error
RE: Runtime Error


Statement ES CE RE
System.Object o1 = new System.Object(); Y N N
System.Object o2 = new B(); Y N N
System.Object o3 = new D(); Y N N
System.Object o4 = o3; Y N N
B b1 = new B(); Y N N
B b2 = new D(); Y N N
D d1 = new D(); Y N N
B b3 = new System.Object(); N Y N
D d3 = new System.Object(); N Y N
B b3 = d1; Y N N
D d2 = b2; N Y N
D d4 = (D) d1; Y N N
D d5 = (D) b2; Y N N
D d6 = (D) b1; N N Y
B b4 = (B) o1; N N Y
B b5 = (D) b2; Y N N

No comments: