Java SE 8 Programmer II — Question 40

Given the code fragment:
ZonedDateTime depart = ZonedDateTime.of(2015, 1, 15, 3, 0, 0, 0, ZoneID.of("UTC-7"));
ZonedDateTime arrive = ZonedDateTime.of(2015, 1, 15, 9, 0, 0, 0, ZoneID.of("UTC-5")); long hrs = ChronoUnit.HOURS.between(depart, arrive); //line n1
System.out.println("Travel time is" + hrs + "hours");
What is the result?

Answer options

Correct answer: A

Explanation

The code calculates the time difference in hours between the two ZonedDateTime objects, which are set in different time zones. The departure time is 3 AM UTC-7 and the arrival time is 9 AM UTC-5, resulting in a travel time of 4 hours. The other options are incorrect as they do not reflect the actual calculated difference.