Java OCA OCP Practice Question 1841

Question

What is a possible output of this code?

LocalTime time = LocalTime.of(1,2,3,4); 
System.out.println(time); 
  • A. 01:02:03.4
  • B. 01:02:03.000000004
  • C. 01/01/1970 01:02:03.4
  • D. 01/01/1970 01:02:03.000000004


B.

Note

The first thing to notice is that this is a LocalTime object.

Since there is no date component, Options C and D are incorrect.

Four parameters are passed to this LocalTime method.

The first three are the hour, minute, and second.

The fourth is nanoseconds, which are fractions of a second.

While you aren't expected to do calculations with nanoseconds, you should know that a fraction of a second is at the end of the output.

Option A is incorrect because .4 is 40 percent of a second.

That's far larger than 4 nanoseconds.

Option B is correct.




PreviousNext

Related