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-
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.
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.
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.
If date2 was intialised correctly then answer would be A
upvoted 1 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
baledevit
Highly Voted 2 years, 3 months agoPhilip0908
Highly Voted 2 years, 4 months agoMPignaProTech
Most Recent 2 months, 2 weeks agotawa_z58
1 year agoAhmadTechie
1 year, 1 month agoduydn
1 year, 4 months agoVicky_65
1 year, 9 months agoAnkit1010
1 year, 11 months agoanmoldev2java
2 years, 1 month agocarloswork
2 years, 2 months agoiSnover
2 years, 3 months agoRdharma
2 years, 3 months agoiSnover
2 years, 3 months agoshivkumarx
2 years, 3 months ago