O'Reilly logo

Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition by Rolf W. Rasmussen, Khalid A. Mughal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Review Questions

6.17 Given the following program, which statement is true?
// Filename: MyClass.java
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 {}

Select the one correct answer.

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

  2. The program will throw a java.lang.ClassCastException in the assignment at (2) when run.

  3. The program will throw a java.lang.ClassCastException in the assignment at (3) when run.

  4. The program will compile and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required