Given class Alien String invadeshort ships return a few String invadeshort

Given class alien string invadeshort ships return a

This preview shows page 11 - 14 out of 64 pages.

24. Given:class Alien {String invade(short ships) { return "a few"; }String invade(short... ships) { return "many"; }}class Defender {public static void main(String [] args) {System.out.println(new Alien().invade(7));} }What is the result?A. manyB. a fewC. Compilation failsD. The output is not predictableE. An exception is thrown at runtimeAnswer:C is correct, compilation fails. The var-args declaration is fine, but invade takes a short,so the argument 7 needs to be cast to a short. With the cast, the answer is B, 'a few˚A, B, D, and E are incorrect based on the above. '.25. Given:1. class Dims {2. public static void main(String[] args) {3. int[][] a = {{1,2,}, {3,4}};4. int[] b = (int[]) a[1];5. Object o1 = a;
Background image
6. int[][] a2 = (int[][]) o1;7. int[] b2 = (int[]) o1;8. System.out.println(b[1]);9. } }What is the result?2425. Given:class Mixer {Mixer() { }Mixer(Mixer m) { m1 = m; }Mixer m1;public static void main(String[] args) {Mixer m2 = new Mixer();Mixer m3 = new Mixer(m2); m3.go();Mixer m4 = m3.m1; m4.go();Mixer m5 = m2.m1; m5.go();}void go() { System.out.print("hi "); }}What is the result?tries
Background image
} }What is the result?. The
Background image
Image of page 14

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture