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.
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)- A90% (35)
- B3% (1)
- C5% (2)
- D3% (1)
Why each option
The Java compiler automatically imports `java.lang` and the unnamed package (default package) into every source file.
The `java.lang` package contains fundamental classes for the Java platform, such as `Object`, `String`, and `System`, and is always implicitly imported.
The `java.awt` package is not automatically imported; it must be explicitly imported if its classes are to be used.
The `java.util` package is not automatically imported; it must be explicitly imported if its classes are to be used.
The `javax.net` package is not automatically imported; it must be explicitly imported if its classes are to be used.
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
Community Discussion
No community discussion yet for this question.