Repaso
EspaƱol
Java CoreFoundationsJV-50

What are a package and an import in Java?

Options

  1. A package groups classes; import allows short class names (Correct option)
  2. A package is a delivery box; import deletes a class
  3. A package is a database table; import creates one
  4. Both are comment styles that are used to document code

Answer

A package is a namespace that groups related classes; import lets you use a class from another package by its short name

Why

The Java tutorial: a package is a namespace that organizes a set of related classes and interfaces, like folders on a computer.

Example: java.util.List is the class List in the package java.util. After import java.util.List; you can write just List.

Your own code is organized in packages too, usually named after the company domain reversed, like com.mycompany.shop.

Remember

Package = folder-like namespace. import = use a class from it.

Key terms

Practice this question in Repaso