Multiple choice technology programming languages

Given: 55. int []x= {1, 2,3,4, 5}; 56.int y[] =x; 57. System.out.println(y[2]); Which is true?

  1. Line 57 will print the value 2

  2. Line 57 will print the value 3

  3. Compilation will fail because of an error in line 55

  4. Compilation will fail because of an error in line 56

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

Array references in Java are reference types. When y[] = x executes, both variables point to the same array. Since arrays are 0-indexed, y[2] accesses the third element with value 3.