✏️ Explanatory Question
[Packages]
Question:
State the purpose of the following keywords in Java:
(a) package
(b) import
[Packages]
Question:
State the purpose of the following keywords in Java:
(a) package
(b) import
Answer:
(a) package
The package keyword is used to group related classes and interfaces
together into a single namespace.
Purpose:
Example:
package mypack;
(b) import
The import keyword is used to access classes and interfaces
from another package.
Purpose:
Example:
import java.util.Scanner;
Now the Scanner class can be used directly in the program.
Conclusion:
package → Creates and organizes packagesimport → Accesses classes from other packages