Java OCA OCP Practice Question 2162

Question

How many of the following can fill in the blank to make this code compile?.

public boolean isItMyBirthday(LocalDateTime dateTime) { 
   return now.getMonth() == dateTime.getMonth() 
          && now.getDayOfMonth() == dateTime.getDayOfMonth(); 
} 
I.   LocalDate now = LocalDate.now();
II.   LocalDate now = new LocalDate();
III.   LocalDateTime now = LocalDateTime.now();
IV.   LocalDateTime now = new LocalDateTime();
V.   ZonedDate now = ZonedDate.now();
VI.   ZonedDate now = new ZonedDate();

  
  • A. None
  • B. One
  • C. Two
  • D. Three
  • E. Four
  • F. Five


C.

Note

Java 8 date and time classes are immutable.

They use a static factory method to get the object reference rather than a constructor.

This makes II, IV, and VI incorrect.

Further, there is not a ZonedDate class.

There is a ZonedDateTime class.

This additionally makes V incorrect.

Both I and III compile, so Option C is correct.




PreviousNext

Related