Packages and Import Statements provide a comprehensive set of multiple-choice questions to test your understanding of these essential concepts in Java programming. Packages and import statements play a crucial role in organizing and managing Java code by allowing you to group related classes together and access classes from different packages. These MCQs cover various aspects of creating, using, and importing packages, helping you strengthen your knowledge of Java’s modular structure and how to effectively utilize import statements.
1.) What’s the main purpose of Java packages?
A) Group-related classes
B) Create variables
C) Handle exceptionsn3
D) Implement interfaces
2.)Purpose of import java.util.*;?
A) Import all classes1
B) Import wildcard classes
C) Import with sub-packages
D) Import the current package
3.) What does the import statement do?
A) Includes package contents
B) Creates objects
C) Imports all classes
D) Defines new packages
4.) Correct syntax for importing MyClass from com.example?
A) import MyClass from com.example;le;on1
B) import com.example.MyClass;
C) import package com.example.MyClass;
D) import com.example package MyClass;
5.) To use MyClass from myPackage, which import is needed?
A) import myPackage.MyClass;
B) import myPackage;
C) import MyClass from myPackage;
D) import class myPackage.MyClass;
6.) Use classes from default package in Java?
A) Yes, without restrictions
B) Yes, within the same package
C) No, inaccessible
D) No, only in default classes
7.) Do classes in same package need imports?
A) No, imports not needed
B) Yes, mandatory for all
C) Not allowed
D) Only for abstract classes
8.) What is the default package in Java?
A) It is a package that contains all built-in classes.
B) It is a package created automatically for each new project.
C) It is a package that does not have a name.
D) It is a package used for importing external libraries.
9.) Valid access to MyClass in myPackage without import?
A) myPackage.MyClass
B) MyClass.from(myPackage);
C) import myPackage.MyClass;
D) MyClass myPackage;
10.) What is the purpose of using “import static” statements in Java?
A) To import all classes from a package.
B) To import classes with static methods only.
C) To import static members of a class.
D) To import classes for reflection purposes.