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

Given the code fragment:

What is the result?

    Correct Answer: A

    The code will not run due to a compilation error. The method format is being invoked without a dot (.) separator from the object, leading to a syntactically invalid line of code. This will result in a compilation error rather than an exception at runtime. The code would work if it was written correctly as: System.out.print(dt.format(DateTimeFormatter.ISO_DATE)); even though the suggested modifications of the date are also incorrect and would not be saved due to the immutability of LocalDateTime objects.

Discussion
v323rsOption: C

Agree, the correct answer C 2014-07-31; System.out.println(dt.format(DateTimeFormatter.ISO_DATE));

carlosworkOption: C

Answer is C (Fixing punctuation and whitespace). To test: public static void main(String[] args) { LocalDateTime dt = LocalDateTime.of(2014, 7, 31, 1, 1); dt.plusDays(30); dt.plusMonths(1); System.out.print(dt.format(DateTimeFormatter.ISO_DATE)); }

duydnOption: A

LocalDateTime cannot convert o LocalDate -> A (maybe the answer is Compilation error)

iSnoverOption: A

The correct answer is the letter A, I'll explain why, the code would compile but notice that the last line doesn't have a "." to invoke the "format" method, then the code would not compile, but as it doesn't have the correct answer, I would mark the answer that most closely matches the reality of this code which is an exception, because in it the code doesn't run either.

DanielLeeeeOption: C

answer is C: 2014-07-31

EmilioDeBakuOption: A

answer is.... A

SSJ5Option: A

There is type in this case. If it was System.out.println(dt.format(DateTimeFormatter.ISO_DATE)); then the answer is C otherwise compilation error

x979Option: C

LocalDateTime is immutable. dt.plusdays(30) saves to no where

x979Option: A

LocalDateTime is immutable. dt.plusdays(30) saves to no where

zhiradevOption: C

C is correct

fvelazqueznavaOption: A

ISO_DATE NEEDS TO BE ISO_DATE_TIME

Sreeni_AOption: C

Answer is C

akbiyikOption: C

Answer is C

UAK94Option: C

Answer is C. Because dt is immutable. There is no assignment to dt.

ivaJavaOption: A

Seriously?? error: incompatible types: LocalDateTime cannot be converted to LocalDate LocalDate time = LocalDateTime.of(2021,12,23,12,15);

yakitoriOption: C

import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; public class Found { public static void main(String[] args) { LocalDateTime dt = LocalDateTime.of(2014, 7,31,1,1); dt.plusDays(30); dt.plusMonths(1); System.out.println(dt.format(DateTimeFormatter.ISO_DATE)); } } 2014-07-31

testmariaOption: A

LocalDateTime is not a subclass of LocalDate.. Answer is A