Question 54Asked in UGC NET Computer Science, June 2017 (Paper II & III, Selected Questions)

Given the array of integers 'array' shown below : 13 7 27 2 18 33 9 11 22 8

Given the array of integers 'array' shown below : 13 7 27 2 18 33 9 11 22 8 What is the output of the following Java statements? int [ ] p = new int [10]; int [ ] q = new int [10]; for (ink k = 0; k < 10; k++) p[k] = array [k]; q = p; p[4] = 20; System out. println (array [4]+ "." + q[4]);
  1. A20 : 20
  2. B18 : 18
  3. C18 : 20
  4. D20 : 18
Show answerHide answer

Correct answer: (C) 18 : 20

Explanation

The loop copies all values of 'array' into p. After q = p, q refers to the same array object as p, so p[4] = 20 also makes q[4] = 20. 'array' itself is unchanged, so array[4] = 18. The output is 18 : 20.

From UGC NET Computer Science PYQ, June 2017 (Paper II & III, Selected Questions)

This is question 54 of UGC NET Computer Science PYQ, June 2017 (Paper II & III, Selected Questions). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.