Page 1 of 1

About Question enthuware.ocpjp.v11.2.3617 :

Posted: Mon Sep 20, 2021 2:33 pm
by samba2

Code: Select all

List<Integer> aList = List.of(40, 30, 20);  //1
List<Integer> bList = List.copyOf(aList); //2
bList.sort((Integer::compare)); //3
System.out.println( bList ); //4
aList.sort((Integer::compare)); //5
System.out.println( aList ); //6
When working on that question I saw that both lists are read-only. However, line //5 is never reached as line //3 throws a RuntimeException which finishes execution (not handled at least in the visible code). Hence, I opted for "Only line //3 will cause an java.lang.UnsupportedOperationException to be thrown at runtime."

Am I mistaken here?

Re: About Question enthuware.ocpjp.v11.2.3617 :

Posted: Tue Sep 21, 2021 1:54 am
by admin
Hi, yes, in such questions where the option statements point out individual lines, you can safely assume that the options are exactly about those lines if they are executed. As opposed to the problem statement that asks you about the output of executing a program.

This is specially true when the given code is not really a full executable program but just a code snippet.