Java OCA OCP Practice Question 2795

Question

What is the output of the following code?

LocalDate date = LocalDate.of(2020, Month.APRIL, 30); 
date.plusDays(2); 
date.plusYears(3); 
System.out.println(date.getYear() + " " 
   + date.getMonth() + " "+ date.getDayOfMonth()); 
A.  2020 APRIL 2 //from w  w  w.  j a  v a 2  s.c om

B.  2020 APRIL 30 

C.  2020 MAY 2 

D.  2023 APRIL 2 
E.  2023 APRIL 30 

F.  2023 MAY 2 

G.  A runtime exception is thrown. 


B.

Note

The date starts out as April 30, 2020.

Since dates are immutable and the plus methods have their return values ignored, the result is unchanged.

Therefore, Option B is correct.




PreviousNext

Related