nerdexam
Oracle

1Z0-803 · Question #242

Given the code fragment: public class Test { static String[][] arr =new String[3][]; private static void doPrint() { //insert code here } public static void main(String[] args) { String[] class1 = {"A

The correct answer is B. private static void doPrint() {. not A: The following line causes a compile error: System.out.println(str[j]); Not C: Compile erro line: for (String[] sub: arr[][]) not D: Output: C

Creating and Using Arrays

Question

Given the code fragment:

public class Test { static String[][] arr =new String[3][]; private static void doPrint() { //insert code here } public static void main(String[] args) { String[] class1 = {"A","B","C"}; String[] class2 = {"L","M","N","O"}; String[] class3 = {"I","J"}; arr[0] = class1; arr[1] = class2; arr[2] = class3; Test.doPrint(); } } Which code fragment, when inserted at line //insert code here, enables the code to print COJ?

Options

  • Aint i = 0;
  • Bprivate static void doPrint() {
  • Cint i = 0;
  • Dfor (int i = 0;i < arr.length-1;i++) {

How the community answered

(22 responses)
  • A
    14% (3)
  • B
    73% (16)
  • C
    5% (1)
  • D
    9% (2)

Explanation

not A: The following line causes a compile error: System.out.println(str[j]); Not C: Compile erro line: for (String[] sub: arr[][]) not D: Output: C

Topics

#2D arrays#nested loops#array indexing

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice