nerdexam
Oracle

1Z0-803 · Question #144

Given: public class Test { } Which two packages are automatically imported into the Java source file by the Java compiler?

The correct answer is A. java.lang E. the package with no name. The Java compiler automatically imports java.lang and the unnamed package (default package) into every source file.

Java Basics

Question

Given:

public class Test { } Which two packages are automatically imported into the Java source file by the Java compiler?

Options

  • Ajava.lang
  • Bjava.awt
  • Cjava.util
  • Djavax.net
  • Ethe package with no name

How the community answered

(39 responses)
  • A
    90% (35)
  • B
    3% (1)
  • C
    5% (2)
  • D
    3% (1)

Why each option

The Java compiler automatically imports `java.lang` and the unnamed package (default package) into every source file.

Ajava.langCorrect

The `java.lang` package contains fundamental classes for the Java platform, such as `Object`, `String`, and `System`, and is always implicitly imported.

Bjava.awt

The `java.awt` package is not automatically imported; it must be explicitly imported if its classes are to be used.

Cjava.util

The `java.util` package is not automatically imported; it must be explicitly imported if its classes are to be used.

Djavax.net

The `javax.net` package is not automatically imported; it must be explicitly imported if its classes are to be used.

Ethe package with no nameCorrect

Any class defined without a package declaration is part of the 'unnamed package' (also known as the default package), and all classes within this unnamed package are implicitly imported and accessible to each other.

Concept tested: Java automatic package imports

Source: https://docs.oracle.com/javase/specs/jls/se17/html/jls-7.html#jls-7.3

Topics

#package import#java.lang#default package

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice