[ Team LiB ] Page 334
[ Team LiB ] Review Questions 6.17 Given the following program, which statement is true? // Filename: MyClass.javapublic 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. a. b. c. d. The program will fail to compile because of the assignment at (1). The program will throw a java.lang.ClassCastException in the assignment at (2) when run. The program will throw a java.lang.ClassCastException in the assignment at (3) when run. The program will compile and run without errors, even if the (B[]) cast 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 (B[]) cast in statements at (2) and (3) is removed. 6.18 Which is the first line that will cause compilation to fail in the following program? // Filename: MyClass.javaclass MyClass { public static void main(String[] args) { MyClass a; MySubclass b; a = new MyClass(); // (1) b = new MySubclass(); // (2) a = b; // (3) Page 335
Note: If you are looking for cheap and reliable provider to host and run your servlet application check Vision servlet hosting services