Exam 1z0-829 All QuestionsBrowse all questions from this exam
Question 4

Given the code fragment:

What is the result?

    Correct Answer: A

    The method truncatedTo(ChronoUnit.MINUTES) truncates the Instant object to the nearest minute. Given the loginTime of 2021-01-12T21:58:18.817Z and the logoutTime of 2021-01-12T21:58:19.880Z, both will be truncated to 2021-01-12T21:58:00Z. After truncation, loginTime and logoutTime are equal, so logoutTime.isAfter(loginTime) will return false, and the else statement will execute, printing 'Can't logout'.

Discussion
minhdevOption: A

A is correct: truncatedTo() coverts the logoutTime=LoginTime => else is reached.

james2033Option: A

package q04; import java.time.Instant; import java.time.temporal.ChronoUnit; public class Q04 { public static void main(String[] args) throws InterruptedException { // Login time: 2021-01-12T21:58:18.817Z Instant loginTime = Instant.now(); Thread.sleep(1000); // Logout time: 2021-01-12T21:58:19.880Z Instant logoutTime = Instant.now(); loginTime = loginTime.truncatedTo(ChronoUnit.MINUTES); // line n1 logoutTime = logoutTime.truncatedTo(ChronoUnit.MINUTES); if (logoutTime.isAfter(loginTime)) { System.out.println("Logged out at: " + logoutTime); } else { System.out.println("Can't logout"); } } } // Result: // Can't logout

SampsOption: A

A is correct

UtemanOption: A

Outputs Can't logout

xplorerpjOption: A

A is correct