From the course: Java SE 11 Developer (1Z0-819) Cert Prep

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Question deep dive

Question deep dive

- Time for another exam-style question. What happens here? First, we make an unmodifiable list of the integers 1, 2, and 3 and store that in a var declared variable "la." Var is valid in this case, there's no problem there, so that one does not cause any failures. Then we take a list copy of "la." Well, in this particular case the list "of" already created an unmodifiable list, so this guy, "copy of," will produce a situation where "lb" and "la" have the exact same values. They refer to the same object. That would tell us that this would produce true if there's no other problems. Next, we create a new int array with no elements in it. And we assign that to "ia1," which is declared using the var pseudo type. Is that safe? Well yes, because we have an explicit statement that this is an int array, we can use var for that. The next thing that happens is we do an arrays copy of ia1 and attempt to assign the result to ia2. Turns out this is where the key to this question lies. The copy of…

Contents