nerdexam
Oracle

1Z0-819 · Question #20

Given: ``java package test; import java.time.*; public class Diary { private LocalDate now = LocalDate.now(); public LocalDate getDate() { return now; } } ` and `java package test; public class…

The correct answer is A. Class Tester does not need to import java.time.LocalDate because it is already visible to members of the package test. See the full explanation below for the reasoning.

Question

Given:
package test;

import java.time.*;

public class Diary {
 private LocalDate now = LocalDate.now();

 public LocalDate getDate() {
 return now;
 }
}
and
package test;

public class Tester {
 public static void main(String[] args) {
 Diary d = new Diary();
 System.out.println(d.getDate());
 }
}
Which statement is true?

Options

  • AClass Tester does not need to import java.time.LocalDate because it is already visible to members of the package test.
  • BAll classes from the package java.time.*, are loaded to the class Diary.
  • CBoth classes need to be in the java.time package to work.
  • DTester must import java.time.LocalDate in order to compile.

How the community answered

(22 responses)
  • A
    82% (18)
  • B
    5% (1)
  • C
    9% (2)
  • D
    5% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice