Java Multiple Choice Questions & Answers on Collections Interface for Freshers

1. Which of these interface declares core method that all collections will have?

a) set
b) EventListner
c) Comparator
d) Collection
Answer: d

Explanation: Collection interfaces defines core methods that all the collections like set, map, arrays etc will have.
2. Which of these interface handle sequences?

a) Set
b) List
c) Comparator
d) Collection
Answer: b
3. Which of these interface is not a part of Java’s collection framework?

a) List
b) Set
c) SortedMap
d) SortedList
Answer: d

Explanation: SortedList is not a part of collection framework.
4. Which of these interface must contain a unique element?

a) Set
b) List
c) Array
d) Collection
Answer: a

Explanation: Set interface extends collection interface to handle sets, which must contain unique elements.
5. Which of these is Basic interface that all other interface inherits?

a) Set
b) Array
c) List
d) Collection
Answer: d

Explanation: Collection interface is inherited by all other interfaces like Set, Array, Map etc. It defines core methods that all the collections like set, map, arrays etc will have
6. What is the output of this program?
  1.     import java.util.*;
  2.     class Maps {
  3.         public static void main(String args[]) {
  4.             TreeMap obj = new TreeMap();
  5.             obj.put("A", new Integer(1));
  6.             obj.put("B", new Integer(2));
  7.             obj.put("C", new Integer(3));
  8.             System.out.println(obj.entrySet());
  9.         }
  10.     }
a) [A, B, C]
 b) [1, 2, 3] 
c) {A=1, B=2, C=3}
d) [A=1, B=2, C=3] 

Answer: d

Explanation: obj.entrySet() method is used to obtain a set that contains the entries in the map. This method provides set view of the invoking map.
7. What is the output of this program?
  1.     import java.util.*;
  2.     class vector {
  3.         public static void main(String args[]) {
  4.             Vector obj = new Vector(4,2);
  5.             obj.addElement(new Integer(3));
  6.             obj.addElement(new Integer(2));
  7.             obj.addElement(new Integer(5));
  8.             obj.removeAll(obj);
  9.             System.out.println(obj.isEmpty());
  10.         }
  11.     }
a) 0
b) 1
c) true
d) false
Answer: c

Explanation: firstly elements 3, 2, 5 are entered in the vector obj, but when obj.removeAll(obj); is executed all the elements are deleted and vector is empty, hence obj.isEmpty() returns true.
8. What is the output of this program?
  1.     import java.util.*;
  2.     class Array {
  3.         public static void main(String args[]) {
  4.             int array[] = new int [5];
  5.             for (int i = 5; i > 0; i--)
  6.                 array[5 - i] = i;
  7.             Arrays.sort(array);
  8.             for (int i = 0; i < 5; ++i)
  9.              System.out.print(array[i]);;
  10.         }
  11.     }
a) 12345
b) 54321
c) 1234
d) 5432
Answer: a

Explanation: Arrays.sort(array) method sorts the array into 1,2,3,4,5.
9. What is the output of this program?
  1.     import java.util.*;
  2.     class vector {
  3.         public static void main(String args[]) {
  4.             Vector obj = new Vector(4,2);
  5.             obj.addElement(new Integer(3));
  6.             obj.addElement(new Integer(2));
  7.             obj.addElement(new Integer(5));
  8.             obj.removeAll(obj);
  9.             System.out.println(obj.isEmpty());
  10.         }
  11.     }
a) 0
b) 1
c) true
d) false
Answer: c

Explanation: firstly elements 3, 2, 5 are entered in the vector obj, but when obj.removeAll(obj); is executed all the elements are deleted and vector is empty, hence obj.isEmpty() returns true.
10. What is the output of this program?
  1.     import java.util.*;
  2.     class Bitset {
  3.         public static void main(String args[]) {
  4.             BitSet obj = new BitSet(5);
  5.             for (int i = 0; i < 5; ++i)
  6.                 obj.set(i);
  7.             obj.clear(2);
  8.             System.out.print(obj);
  9.         }
  10.     }
a) {0, 1, 3, 4}
b) {0, 1, 2, 4}
c) {0, 1, 2, 3, 4}
d) {0, 0, 0, 3, 4}
Answer: a

Related

Java Multiple Choice Questions & Answers on Java.util – LinkedList, HashSet & TreeSet Class for Freshers

1. Which of these standard collection classes implements a linked list data structure? a) AbstractListb) LinkedListc) HashSetd) AbstractSet Answer: b 2. Which of these classes implements Set inte...

CSS Multiple Choice Questions & Answers on Measurements in CSS for Freshers

1. Which of the following measurement defines a measurement in centimeters? a) cb) cmc) centid) centimeter Answer: b Explanation: Example: div {margin-bottom: 1cm;} 2. Which of t...

C Programming Questions and Answers on Multidimensional Arrays for Freshers

1. What is the correct syntax to send a 3-dimensional array as a parameter?    (Assuming declaration int a[5][4][3];) a) func(a);b) func(&a);c) func(*a);d) func(**a); Answe...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item