Java Fundamentals
LATEST FINAL ASSESSMENT
REVIEW
Q&S
©2024/2025
, 1. Multiple Choice: What does the expression `Map<String,
Integer> map = new HashMap<>();` instantiate?
a) A HashMap with keys of type String and values of type
Integer
b) A HashMap with keys and values of type String
c) A HashMap with keys and values of type Integer
d) A Map with keys of type String and values of type Integer
ANS: a) A HashMap with keys of type String and values of type
Integer
Rationale: The diamond operator `<>` infers the type
parameters from the context, in this case, String for keys and
Integer for values.
2. Fill-in-the-Blank: The _______ method must be implemented
by a class that implements the interface Comparable.
ANS: compareTo
Rationale: The compareTo method is defined in the Comparable
interface and is used for comparing "this" object with the
specified object for order.
©2024/2025
,3. True/False: In Java, the '==' operator can be used to compare
two strings for equality.
ANS: False
Rationale: The '==' operator compares references, not values,
and thus, it is not reliable for string content comparison. The
`equals()` method should be used instead.
4. Multiple Response: Which of the following are valid Java
identifiers? (Choose all that apply)
a) _identifier
b) 2ndName
c) $alary
d) void
e) Java2Share
ANSs: a) _identifier, c) $alary, e) Java2Share
Rationale: Java identifiers can start with a letter, currency
character, or connecting character like an underscore. '2ndName'
starts with a digit, and 'void' is a reserved keyword.
5. Multiple Choice: Which of these access specifiers can be used
for an interface?
a) private
b) protected
©2024/2025
, c) public
d) All of the above
ANS: c) public
Rationale: Interfaces can only be declared with public or default
(package-private) access, but not with private or protected access.
6. True/False: The hashCode() method of an object is guaranteed
to be unique for each instance.
ANS: False
Rationale: The hashCode() method is not required to produce a
unique integer for each distinct object. Two different objects can
have the same hash code.
7. Fill-in-the-Blank: A class that is declared with the abstract
keyword is known as an _______.
ANS: abstract class
Rationale: An abstract class cannot be instantiated on its own
and can include abstract methods that must be implemented by
subclasses.
8. Multiple Choice: Which collection class allows you to grow or
shrink its size and provides indexed access to its elements?
a) Array
©2024/2025