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.
|
6.18 |
Which is the first line that will cause compilation to fail in the following program? // Filename: MyClass.java class MyClass { public static void main(String[] args) { MyClass a; MySubclass b; a = new MyClass(); // (1) b = new MySubclass(); // (2) a = b; // (3) b = a; // (4) a = new MySubclass(); // (5) b = new MyClass(); // (6) } } class MySubclass extends MyClass {} Select the one correct answer.
|
6.19 |
Given the following definitions and reference declarations, which one of the following assignments is legal? // Definitions: interface I1 {} interface I2 {} class C1 implements I1 {} class C2 implements I2 {} class C3 extends C1 implements I2 {} // Reference declarations: // ... C1 obj1; C2 obj2; C3 obj3; // ... Select the one correct answer.
|
6.20 |
Given the following class definitions and the reference declarations, what can be said about the statement y = (Sub) x? // Class definitions: class Super {} class Sub extends Super {} // Reference declarations // ... Super x; Sub y; // ... Select the one correct answer.
|
6.21 |
Given the following class definitions and declaration statements, which one of these assignments is legal at compile time? // Definitions: interface A {} class B {} class C extends B implements A {} class D implements A {} // Declaration statements: // [...] B b = new B(); C c = new C(); D d = new D(); // [...] Select the one correct answer.
|
6.22 |
Which letters will be printed when the following program is run? // Filename: MyClass.java public class MyClass { public static void main(String[] args) { B b = new C(); A a = b; if (a instanceof A) System.out.println("A"); if (a instanceof B) System.out.println("B"); if (a instanceof C) System.out.println("C"); if (a instanceof D) System.out.println("D"); } } class A {} class B extends A {} class C extends B {} class D extends C {} Select the three correct answers.
|
6.23 |
Given three classes A, B, and C, where B is a subclass of A and C is a subclass of B, which one of these boolean expressions is true when an object denoted by reference o has actually been instantiated from class B as opposed to from A or C? Select the one correct answer.
|
6.24 |
When the following program is run, it will print all the letters I, J, C, and D. Is this statement true or false? public class MyClass { public static void main(String[] args) { I x = new D(); if (x instanceof I) System.out.println("I"); if (x instanceof J) System.out.println("J"); if (x instanceof C) System.out.println("C"); if (x instanceof D) System.out.println("D"); } } interface I{} interface J{} class C implements I {} class D extends C implements J {} Select the one correct answer.
|