Question: Which statement about the following program is true? Select the one correct answer. (a) The program will fail to compile because of the assignment at

Which statement about the following program is true?

public class MyClass { public static void main (String[] args) { A[]

Select the one correct answer.

(a) The program will fail to compile because of the assignment at (1).

(b) When run, the program will throw a java.lang.ClassCastException in the assignment at (2).

(c) When run, the program will throw a java.lang.ClassCastException in the assignment at (3).

(d) The program will compile and run without errors, even if the cast operator (B[]) in the statements at (2) and (3) is removed.

(e) The program will compile and run without errors, but will not do so if the cast operator (B[]) in statements at (2) and (3) is removed.

public class MyClass { public static void main (String[] args) { A[] arrA; B[] arrB; arrA = new A [10]; arrB= new B[20]; arrA = arrB; // (1) arrB = (B[]) arrA; // (2) arrA= new A [10]; arrB= (B[]) arrA; // (3) class A {} class B extends A {}

Step by Step Solution

3.39 Rating (152 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

c The program will throw a javalangClassCastExceptio... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming 8th Questions!