Multiple choice

Which of the following options provides the output of this program, when executed? class Sample5 { private int x, y; public sample5(int x, int y) { x = x; } public String toString() { return "[" + x +" ," + y +" ]"; } public static void main(String []args) { sample5 point = new sample5(10, 20); System.out.println(point); } }

  1. point

  2. Point

  3. [0, 0]

  4. [10, 0]

  5. [10, 20]

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

The assignment x = x; inside the construct reassigns the passed parameter. It does not assign the memberx in sample5. The correct way to perform the assignment is this.x = x;. Field y is not assigned, so its value remains 0.