Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 35

Given the code fragment:

Assume that the system date is June 20, 2014. What is the result?

A.

B.

C. Compilation fails.

D. An exception is thrown at runtime.

    Correct Answer:

    The correct answer is D: An exception is thrown at runtime. The method LocalDate.of expects the parameters in the order of year, month, and day. However, in the given code, the parameters are provided as 6, 20, 2014, which the method will interpret as year 6, month 20, and day 2014. Since the month value 20 is invalid (valid values range from 1 to 12), a DateTimeException will be thrown.

Discussion
baledevit

The correct answer is D. Line 2 generate an DateTimeException at runtime because method have an invalid value for the second parameter MonthOfYear (20)! https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html#of-int-int-int-

Philip0908

Answer is D because when using LocalDate.of, it should be arrange as year, month and day of month(e.g LocalDate.of(2014,6,20)

Vicky_65

D is the correct one

Ankit1010

Correct Answer is D

carloswork

Answer is D. Throw exception at runtime. To test: public static void main(String[] args) { LocalDate date1 = LocalDate.now(); LocalDate date2 = LocalDate.of(6, 20, 2014); LocalDate date3 = LocalDate.parse("2014-06-20", DateTimeFormatter.ISO_DATE); System.out.println("date1 = " + date1); System.out.println("date2 = " + date2); System.out.println("date3 = " + date3); }

anmoldev2java

it will be runtime exception

iSnover

The correct answer is D, on line 2 the parameter passed is in the format mm-dd-yyyy, as they are integers it will compile but it will return an exception because the correct format is yyyy-mm-dd.

tawa_z58

We have a runtime exception, Because the format in which we gave the date in is not correct, it expects to see soemthing like this "2014-06-24", so if we fail to give the argument in that format, an expeption is thrown at runtime. Also, we have a compilation error on the declaration of date3, but since date2's declaration statement is the one which is first executed it means we wont get to the line where the compilation error is. The compilation error is there because we trien to use the DateTimeFormatter yet or date3's type was LocalDate not LocalDateTime.

AhmadTechie

D is correct => month should be between 1-12 and day range is 1-28/31. though there is no restriction on year range

duydn

D is correct, format is: yyyy-MM-dd

Rdharma

Answer is D

iSnover

Answer is D, the code compile because the method "LocalDate.of" received int numbers, but have a try catch of the format "year-month-day" that occur in this code.

shivkumarx

If date2 was intialised correctly then answer would be A