exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 35 discussion

Actual exam question from Oracle's 1z0-808
Question #: 35
Topic #: 1
[All 1z0-808 Questions]

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.

Show Suggested Answer Hide Answer
Suggested Answer: A

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
baledevit
Highly Voted 2 years, 3 months ago
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-
upvoted 5 times
...
Philip0908
Highly Voted 2 years, 4 months ago
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)
upvoted 5 times
...
MPignaProTech
Most Recent 2 months, 2 weeks ago
D is the correct answer
upvoted 1 times
...
tawa_z58
1 year ago
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.
upvoted 2 times
...
AhmadTechie
1 year, 1 month ago
D is correct => month should be between 1-12 and day range is 1-28/31. though there is no restriction on year range
upvoted 2 times
...
duydn
1 year, 4 months ago
D is correct, format is: yyyy-MM-dd
upvoted 2 times
...
Vicky_65
1 year, 9 months ago
D is the correct one
upvoted 4 times
...
Ankit1010
1 year, 11 months ago
Correct Answer is D
upvoted 4 times
...
anmoldev2java
2 years, 1 month ago
it will be runtime exception
upvoted 3 times
...
carloswork
2 years, 2 months ago
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); }
upvoted 4 times
...
iSnover
2 years, 3 months ago
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.
upvoted 3 times
...
Rdharma
2 years, 3 months ago
Answer is D
upvoted 2 times
...
iSnover
2 years, 3 months ago
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.
upvoted 2 times
...
shivkumarx
2 years, 3 months ago
If date2 was intialised correctly then answer would be A
upvoted 1 times
...
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.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago