Given the code fragment:
What is the result?
Given the code fragment:
What is the result?
The code truncates both loginTime and logoutTime to the nearest minute using the truncatedTo(ChronoUnit.MINUTES) method. Since the logoutTime is only 1 second later than the loginTime, both truncated values will be the same, thus logoutTime.isAfter(loginTime) will return false. Therefore, the output will be "Can't logout".
Answer is C tested. after truncatedTo are called, LoginTime and LogoutTime are the same.
Answer is C, public class Test { public static void main (String[] args) throws InterruptedException { Instant loginTime = Instant.now(); Thread.sleep(1000); Instant logoutTime = Instant.now(); loginTime = loginTime.truncatedTo(ChronoUnit.MINUTES); logoutTime = logoutTime.truncatedTo(ChronoUnit.MINUTES); if (logoutTime.isAfter(loginTime)) System.out.println("Logged out at: " + logoutTime); else System.out.println("Can't logout"); } }
Answer is C.
C is the answer
Answer is C tested.