## Question 2: You have been given below code, what is the behavior expected?

Question 2: You have been given below code, what is the behavior expected?

import java.time.ZoneId;

import java.time.ZonedDateTime;

import java.time.temporal.ChronoUnit;

public class Welcome {

public static void main(String[] args) {

ZonedDateTime startTime = ZonedDateTime.of(2016, 1, 01, 2, 0, 0, 0, ZoneId.of("UTC-4"));

ZonedDateTime endTime = ZonedDateTime.of(2016, 1, 01, 8, 0, 0, 0, ZoneId.of("UTC-1"));

long hrs = ChronoUnit.HOURS.between(startTime, endTime); // line n1

System.out.println("Total time difference is " + hrs + " hours");

}

}

1. Total time difference is 4 hours

2. Total time difference is 3 hours

3. Total time difference is 2 hours

4. An exception is thrown at line n1.

Correct Answer : 2 Exp : ZonedDateTime.of(2016, 1, 01, 2, 0, 0, 0, ZoneId.of("UTC-4")); -> UTC Time = 2+4 = 6

ZonedDateTime.of(2016, 1, 01, 8, 0, 0, 0, ZoneId.of("UTC-1") -> UTC Time = 8+1 =9

9-6=3

I have cleared my Java 1Z0-808 Certification exam with 92% using this simulator

I have cleared my Java 1Z0-809 Certification exam with 96% using this simulator

You have no rights to post comments