Q.– Given:-
public class C extends A {
public void test( ) {
System.out.println("C ");
}
public static void main(String[] args) {
A b1 = new A( );
A b2 = new C( );
A b3 = (B) b2; //line n1
b1 = (A) b2; //line n2
b1.test( );
b3.test( );
}
}
What is the result?
A) C
C
D) A ClassCastException is thrown only at line n2.
C) A
B
B) A
C
E) A ClassCastException is thrown only at line n1.
⧪ please give your answer in a comment section.
public class C extends A {
public void test( ) {
System.out.println("C ");
}
public static void main(String[] args) {
A b1 = new A( );
A b2 = new C( );
A b3 = (B) b2; //line n1
b1 = (A) b2; //line n2
b1.test( );
b3.test( );
}
}
What is the result?
A) C
C
D) A ClassCastException is thrown only at line n2.
C) A
B
B) A
C
E) A ClassCastException is thrown only at line n1.
⧪ please give your answer in a comment section.
5 Comments
Option B
ReplyDeleteB
ReplyDeleteE
ReplyDeleteE
ReplyDeleteE
ReplyDelete