About Question enthuware.ocpjp.i.v11.2.3105 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
dimitrilc
Posts: 34
Joined: Sat Jun 06, 2020 4:51 pm
Contact:

About Question enthuware.ocpjp.i.v11.2.3105 :

Post by dimitrilc »

Greetings, is this explanation,
The List.of/Set.of methods return an unmodifiable List/Set. So, if you try to clear the List returned by List.of, an OperationNotSupportedException will indeed be thrown.
talking about something like this?

Code: Select all

//Will run fine
ArrayList<String> als = new ArrayList<>(List.of("a", "b", "c"));
als.clear();

//Throws java.lang.UnsupportedOperationException at runtime
List<String> als2 = List.of("a", "b", "c");
als2.clear();

admin
Site Admin
Posts: 10461
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3105 :

Post by admin »

Yes, that is correct. (The statement should say UnsupportOperationException instead of OperationNotSupportedException though). Fixed.

nnavlani
Posts: 12
Joined: Sat Aug 02, 2025 11:21 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3105 :

Post by nnavlani »

a clarification. So the answer in this case should be 3, or, "It will throw an java.lang.UnsupportedOperationException at //2." cause once an exception is there, then the regular flow is broken, and it will try to go to the catch or finally (if there) or out to main, but the next line of printing will not be executed.

admin
Site Admin
Posts: 10461
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3105 :

Post by admin »

No, the given code will not throw an UnsupportedOperationException. Please go through the detailed explanation given for option 4.

Post Reply