Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 74

Given the code fragment:

What is the result?

    Correct Answer: B

    In the given code fragment, two integer arrays, nums1 and nums2, are initialized with different values. After the statement nums2 = nums1, the reference nums2 is updated to point to the same array as nums1. Hence, the for loop will iterate over the elements of the array referenced by nums2, which is now the same as nums1. Therefore, the output sequence will be the elements of nums1: 1, 2, 3. The correct result is 1:2:3:

Discussion
ManuTovOption: D

Assignment statement `nums2 = nums1`, where there's a space and both arrays will now point to the same memory location.

GaelBernardOption: B

Tested code provided by rachuk Even though both arrays have different sizes, there's no problem in reassigning their variables. Variables are still nothing else than references to objects.

dsmsOption: C

Answer C public static void main(String[] args) { int nums1[] = {1, 2 ,3}; int nums2[] = {1, 2, 3 ,4 ,5}; nums 2 = nums 1; // not defined. The variable has a space between nums and 2 for (int i : nums2) { System.out.print(i + ":"); } }

yanoolthecool

There's space between the numbers 1 and 2 and the nums

KolodetsOption: C

Compilation fails: no variables "num 1" and "num 2" defined

jackymak

That maybe correct.

rachukOption: B

Correct answer is B, code for testing: public static void main(String[] args) { int nums1[] = {1, 2 ,3}; int nums2[] = {1, 2, 3 ,4 ,5}; nums2 = nums1; for (int i : nums2) { System.out.print(i + " : "); } }

akbiyikOption: C

Compilation fails. It should be nums2 instead of nums 2.

iSnoverOption: B

B is corrent, in line 3 "nums2" becomes a reference of "nums1".

yanoolthecoolOption: B

An online complier gave me B.

Terry8420Option: B

Answer is B , because array is a object

Sreeni_AOption: B

Answer : B and tested locally

pbbvrOption: C

or C if there is a typo error

pbbvrOption: B

Answer: B

Vicky_65Option: B

correct one is B

CreazyyyyGirlOption: B

B is correct

Annie432Option: A

Ran this program I was surprised with the result but A is correct