What is the result?

Given the code fragment:

What is the result?
A. An exception is thrown at runtime
B. 07-31-2014
C. 2014-07-31
D. 2014-09-30

Download Printable PDF. VALID exam to help you PASS.

7 thoughts on “What is the result?

  1. Aside from the many unintentional compiler errors, everything here is legal. The trick being, pretending to change the value of “dt”.

  2. Answer C:

    Date classes are immutable, meaning that any manipulations on its objects need to be reassigned to the original reference variable, or to a new reference variable; else, the result of the manipulation will be ignored and lost.
    The “dt.plusDays(30)” as well as the “dt.plusMonths(1)” lines were both executed nicely, and they have both returned new values, but these values are actually new objects! Therefore, “dt”‘s original value has never been manipulated, and the result remains the same.

  3. import java.time.LocalDateTime;
    import java.time.format.DateTimeFormatter;

    public class Test {

    public static void main (String[] args){
    LocalDateTime dt = LocalDateTime.of(2014, 07, 31, 1, 1);

Leave a Reply

Your email address will not be published. Required fields are marked *

The reCAPTCHA verification period has expired. Please reload the page.