Java Packages MCQ Questions
This section focuses on "packages" in Java programming language. These Multiple Choice Questions (MCQ) should be practiced to improve the Java programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. Package in Java is a mechanism to encapsulate a ______________.
A. Classes
B. Sub Packages
C. Interfaces
D. All of the above
View Answer
Ans : D
Explanation: Package in Java is a mechanism to encapsulate a group of classes, sub packages and interfaces.
2. Which of these keywords is used to define packages in Java?
A. pkg
B. Pkg
C. package
D. Package
View Answer
Ans : C
Explanation: package keywords is used to define packages in Java.
3. Package names and directory structure are closely related.
A. TRUE
B. FALSE
C. can be true or false
D. can not say
View Answer
Ans : A
Explanation: Package names and directory structure are closely related is true statement.
4. An _______________ statement can be used to access the classes and interface of a different package from the current package.
A. instanceOf
B. import
C. extends
D. implement
View Answer
Ans : B
Explanation: This is the keyword which can be used to access the interface of a different package from the current package.
5. Which of the following packages is used to includes classes to create user interface like Button and Checkbox?
A. java.lang
B. java.net
C. java.awt
D. java.io
View Answer
Ans : C
Explanation: java.awt Includes classes to create user interface like Button and Checkbox
6. Which of the following packages is used to includes utility classes like Calendar, Collection, Date?
A. java.lang
B. java.net
C. java.awt
D. java.util
View Answer
Ans : D
Explanation: java.util Includes utility classes like Calendar, Collection, Date.
7. Which of this access specifies can be used for a class so that its members can be accessed by a different class in the same package?
A. Public
B. Protected
C. No Modifier
D. All of the mentioned
View Answer
Ans : D
Explanation: Either we can use public, protected or we can name the class without any specifier.
8. Which of the following is the correct way of importing an entire package "pkg"?
A. import pkg.
B. Import pkg.
C. import pkg.*
D. Import pkg.*
View Answer
Ans : C
Explanation: Operator * is used to import the entire package.
9. Which of the following is false statement about package in java?
A. Packages are used for preventing naming conflicts
B. Providing controlled access: protected and default have package level access control.
C. Packages cannot be considered as data encapsulation
D. Both B and C
View Answer
Ans : C
Explanation: Packages cannot be considered as data encapsulation is false statement about package in java.
10. Packages that are inside another package are the _________
A. packages
B. nested packages
C. util subpackages
D. subpackages
View Answer
Ans : D
Explanation: Packages that are inside another package are the subpackages.
Discussion