Objects and Collections Questions

Practice Objects and Collections MCQs with answers and explanations. Page 2 of 2.

Category
Java Programming
Topic
Objects and Collections
Page
2 / 2
Mode
Practice

Questions

Open any question to view the answer and explanation.

In Java, what does this code print when an anonymous class overrides hashCode()? public static void main(String[] args) { Object obj = new Object() { public int hashCode() { return 42; } }; System.out.println(obj.hashCode()); }
Open
View answer
Java equality vs hashing: For two instances of the same class with properly overridden equals() and hashCode(), which statements are logically correct?
Open
View answer
Given properly implemented equals() and hashCode(), the code prints "x = 1111". Which statement must always be true? x = 0; if (x1.hashCode() != x2.hashCode()) x = x + 1; if (x3.equals(x4)) x = x + 10; if (!x5.equals(x6)) x = x + 100; if (x7.hashCode() == x8.hashCode()) x = x + 1000; System.out.println("x = " + x);
Open
View answer
Choosing the correct facts about properly overridden hashCode() and equals(): which two statements are valid in Java?
Open
View answer
Java Collections Framework: Which statement accurately describes java.util.HashSet?
Open
View answer
Iterator vs. ListIterator in Java: Which statements are correct about their capabilities and APIs?
Open
View answer
Java Collections Framework: Which statement accurately describes java.util.ArrayList?
Open
View answer
Which statements about the hashCode() method are incorrect for Java types?
Open
View answer
Considering these two classes, which statement is true? class Test1 { public int value; public int hashCode() { return 42; } } class Test2 { public int value; public int hashcode() { return (int)(value ^ 5); } }
Open
View answer

Practice smarter

Solve a few questions daily and revisit weak topics regularly to improve accuracy.