HashMap MCQs

HashMap MCQs

These HashMap multiple-choice questions and their answers will help you strengthen your grip on the subject of HashMap. You can prepare for an upcoming exam or job interview with these HashMap MCQs.
So scroll down and start answering.

1: Which of the following methods are defined in the Object class?

A.   Equals

B.   Finalize

C.   ToString

D.   Clone

E.   All of the above.

2: Which of the following methods neither takes any parameter nor returns anything?

A.   Constructor

B.   Catch

C.   Finalize

D.   None of these

3: When an object is stored, are all of the objects that are reachable from that object stored as well?

A.   True

B.   False

4: Which of the following are passed as an argument to the paint( ) method?

A.   A Canvas object

B.   A Graphics object

C.   An Image object

D.   A paint object

5: What are the programming constructs?

A.   Sequential

B.   Selection -- if and switch statements

C.   Iteration -- for loop, while loop and do-while loop

6: What is the data type for the parameter of the sleep() method?

A.   Long

B.   String

C.   Int

D.   Char

7: What is the initial contact point for handling a web request in a Page-Centric architecture?

A.   A JSP page.

B.   A JavaBean.

C.   A servlet.

D.   A session manager.

8: HashMap is thread-safe where as Hashtable is not10, Which of the following assignment statements is invalid?

A.   Double D = 45456.444;

B.   Long L = 45784;

C.   Int I = L;

D.   Int J = (int) D;


What will be the output of the program?

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);




Prints: false,false,false


Prints: false,false,true


Prints: false,true,false


Prints: true,false,false

10: Which will legally declare, construct, and initialize an array?

A.   Int [] myList = {

B.   Int [] myList = (5, 8, 2);

C.   Int myList [] [] = {4,9,7,0};

D.   Int myList [] = {4, 3, 7};

11: Which one is a valid declaration of a boolean?

A.   Boolean b1 = 0;

B.   Boolean b2 = 'false';

C.   Boolean b3 = false;

D.   Boolean b4 = Boolean.false();

E.   Boolean b5 = no;

12: Which cannot directly cause a thread to stop executing?

A.   Calling the SetPriority() method on a Thread object.

B.   Calling the wait() method on an object.

C.   Calling notify() method on an object.

D.   Calling read() method on an InputStream object.

13: Which statement is true?

A.   A try statement must have at least one corresponding catch block.

B.   Multiple catch statements can catch the same class of exception more than once.

C.   An Error that might be thrown in a method must be declared as thrown by that method, or be handled within that method.

D.   Except in case of VM shutdown, if a try block starts to execute, a corresponding finally block will always start to execute.


class A


A( )

{ }


class B extends A

{ }

Which statement is true?


Class B'S constructor is public.


Class B'S constructor has no arguments.


Class B'S constructor includes a call to this( ).


None of these.



What will be the output of the program?

public class Foo


public static void main(String[] args)








System.out.println( "Finally" );







Compilation fails.


The code runs with no output.


An exception is thrown at runtime.