Object Oriented Programming - I (3140705) MCQs

MCQs of Sets and Maps

Showing 1 to 10 out of 13 Questions
1.
Which of these classes implements Set interface?
(a) ArrayList
(b) HashSet
(c) LinkedList
(d) DynamicList
Answer:

Option (b)

2.
Which of these method of HashSet class is used to add elements to its object?
(a) add()
(b) Add()
(c) addFirst()
(d) insert()
Answer:

Option (a)

3.
What will be the output of the following Java program?
    import java.util.*;
    class Output 
    {
        public static void main(String args[]) 
        {
            HashSet obj = new HashSet();
            obj.add("A");
            obj.add("B");
            obj.add("C");
            System.out.println(obj + " " + obj.size());
        }
    }
(a) ABC 3
(b) [A, B, C] 3
(c) ABC 2
(d) [A, B, C] 2
Answer:

Option (b)

4.
Which of these object stores association between keys and values?
(a) Hash table
(b) Map
(c) Array
(d) String
Answer:

Option (b)

5.
Which of these classes provide implementation of map interface?
(a) ArrayList
(b) HashMap
(c) LinkedList
(d) DynamicList
Answer:

Option (b)

6.
Which of these method is used to remove all keys/values pair from the invoking map?
(a) delete()
(b) remove()
(c) clear()
(d) removeAll()
Answer:

Option (b)

7.
Which of these method Map class is used to obtain an element in the map having specified key?
(a) search()
(b) get()
(c) set()
(d) look()
Answer:

Option (b)

8.
Which of these methods can be used to obtain set of all keys in a map?
(a) getAll()
(b) getKeys()
(c) keyall()
(d) keySet()
Answer:

Option (d)

9.
Which of these method is used add an element and corresponding key to a map?
(a) put()
(b) set()
(c) redo()
(d) add()
Answer:

Option (a)

10.
What will be the output of the following Java program?
    import java.util.*;
    class Maps 
    {
        public static void main(String args[]) 
        {
            HashMap obj = new HashMap();
            obj.put("A", new Integer(1));
            obj.put("B", new Integer(2));
            obj.put("C", new Integer(3));
            System.out.println(obj);
        }
    }
(a) {A 1, B 1, C 1}
(b) {A, B, C}
(c) {A-1, B-1, C-1}
(d) {A=1, B=2, C=3}
Answer:

Option (d)

Showing 1 to 10 out of 13 Questions