Objects and Collections Questions

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

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

Questions

Open any question to view the answer and explanation.

Which Java class inherits its equals() and hashCode() directly from java.lang.Object (i.e., does not override them)?
Open
View answer
Which Java collection lets you associate elements with keys while iterating in insertion (FIFO) order?
Open
View answer
Java — Which interface does java.util.Hashtable implement?
Open
View answer
Java — What is the numerical range of the char data type?
Open
View answer
Java — Store elements with no duplicates and natural order. Which interface provides this capability?
Open
View answer
Java — Which Map implementation maintains iteration order of an existing Map?
Open
View answer
Java — Which collection class allows resizing, provides indexed access, but is not synchronized?
Open
View answer
Java — What line of code should replace the missing statement to compile this program? public class foo { public static void main(String[]args)throws Exception { java.io.PrintWriter out = new java.io.PrintWriter(); new java.io.OutputStreamWriter(System.out,true); out.println("Hello"); } }
Open
View answer
Java — Which interface provides capability to store objects using key-value pairs?
Open
View answer
Java — Which of the following are Java reserved words? (run, import, default, implement)
Open
View answer
Java — Which collection class allows key-value associations and provides synchronization?
Open
View answer
Java — Which is a valid declaration of a float value?
Open
View answer
Java TreeSet iteration order and duplicate handling: what sequence is printed? TreeSet map = new TreeSet(); map.add("one"); map.add("two"); map.add("three"); map.add("four"); map.add("one"); // duplicate Iterator it = map.iterator(); while (it.hasNext()) { System.out.print(it.next() + " "); }
Open
View answer
Static array reference default value vs element access: what happens when printing x[0]? public class Test { private static int[] x; // reference not initialized → null public static void main(String[] args) { System.out.println(x[0]); } }
Open
View answer
Which interfaces does Vector.elements() return, and how do instanceof tests evaluate? import java.util.*; class H { public static void main (String[] args) { Object x = new Vector().elements(); System.out.print((x instanceof Enumeration) + ","); System.out.print((x instanceof Iterator) + ","); System.out.print(x instanceof ListIterator); } }
Open
View answer
Packages, access modifiers, and top-level classes: will this code compile? package foo; import java.util.Vector; // Line 2 private class MyVector extends Vector { int i = 1; // Line 5 public MyVector() { i = 2; } } public class MyNewVector extends MyVector { public MyNewVector() { i = 4; // Line 15 } public static void main (String args[]) { MyVector v = new MyNewVector(); // Line 19 } }
Open
View answer
Default values in a newly allocated float array: what exactly prints for f[0]? public class Test { private static float[] f = new float[2]; public static void main (String[] args) { System.out.println("f[0] = " + f[0]); } }
Open
View answer
Which interfaces does ArrayList.iterator() implement? Evaluate the instanceof results. import java.util.*; class I { public static void main (String[] args) { Object i = new ArrayList().iterator(); System.out.print((i instanceof List) + ","); System.out.print((i instanceof Iterator) + ","); System.out.print(i instanceof ListIterator); } }
Open
View answer
Using NULL vs null in Java: what does this program do? public class Test { public static void main (String args[]) { String str = NULL; System.out.println(str); } }
Open
View answer
In Java command-line arguments, what is printed by this program when executed as shown? public class Test { public static void main (String[] args) { String foo = args[1]; String bar = args[2]; String baz = args[3]; System.out.println("baz = " + baz); // Line 8 } } Invocation: > java Test red green blue
Open
View answer

Practice smarter

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