Multiple choice

What is the output of the given program?

int [] array = {1, 2, 3, 4, 5};

System.arraycopy (array, 2, array, 1, 2);

System.out.print (array [1]);

System.out.print (array[4]);

  1. 34

  2. 35

  3. 24

  4. Run time error

  5. Compilation error

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The two elements 3 and 4 (starting from position with index 2) are copied into position index 1 and 2 in the same array. After the array copy command, the array looks like: {1, 3, 4, 4, 5}.Then, element with index 1 is printed: 3. Then, element with index 4 is printed: 5.