[HD-OCP17/21-Fundamentals Pg 422, Sec. 15.4.3 - order-of-closing-the-resources]

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

Moderator: admin

Post Reply
raphaelzintec
Posts: 167
Joined: Sun Apr 21, 2024 10:43 am
Contact:

[HD-OCP17/21-Fundamentals Pg 422, Sec. 15.4.3 - order-of-closing-the-resources]

Post by raphaelzintec »

"Devicecontaining"
add space -> Device containing

radupana
Posts: 28
Joined: Fri Feb 09, 2018 11:50 am
Contact:

Re: [HD-OCP17/21-Fundamentals Pg 422, Sec. 15.4.3 - order-of-closing-the-resources]

Post by radupana »

In the code snippet provided (TestClass and Device), it says that

"""
You should observe the following points:
1. Resources are opened in the order specified in the try clause (Device 1 and then Device 2).
"""

However, this is not because of the order in the try clause, it's because of the order of the constructor calls. We can change the try from

try(d1; Device d2 = new Device(2)){

to

try(Device d2 = new Device(2); d1){

and the output would still be

Device 1 opened
Device 2 opened

because d1 is constructed before d2.

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

Re: [HD-OCP17/21-Fundamentals Pg 422, Sec. 15.4.3 - order-of-closing-the-resources]

Post by admin »

Right. It should be try(Device d1 = new Device(2) , Device d2 = new Device(2)

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 33 guests