Object Oriented Programming - I (3140705) MCQs

MCQs of List, Stacks, Queues and Priority Queues

Showing 31 to 30 out of 40 Questions
31.
What will be the output of the following Java program?
    import java.util.*;
    class Collection_Algos 
    {
        public static void main(String args[]) 
        {
            LinkedList list = new LinkedList();
            list.add(new Integer(2));
            list.add(new Integer(8));
            list.add(new Integer(5));
            list.add(new Integer(1));
            Iterator i = list.iterator();
            Collections.reverse(list);
	    Collections.sort(list);
            while(i.hasNext())
	        System.out.print(i.next() + " ");
        }
    }
(a) 2 8 5 1
(b) 1 5 8 2
(c) 1 2 5 8
(d) 2 1 8 5
Answer:

Option (c)

32.
What will be the output of the following Java program?
    import java.util.*;
    class Collection_Algos 
    {
        public static void main(String args[]) 
        {
            LinkedList list = new LinkedList();
            list.add(new Integer(2));
            list.add(new Integer(8));
            list.add(new Integer(5));
            list.add(new Integer(1));
            Iterator i = list.iterator();
            Collections.reverse(list);
	    Collections.shuffle(list);
            while(i.hasNext())
	        System.out.print(i.next() + " ");
        }
    }
(a) 2 8 5 1
(b) 1 5 8 2
(c) 1 2 5 8
(d) Any random order
Answer:

Option (d)

33.
Which of these return type of hasNext() method of an iterator?
(a) Integer
(b) Double
(c) Boolean
(d) Collections Object
Answer:

Option (c)

34.
Which of these methods is used to obtain an iterator to the start of collection?
(a) start()
(b) begin()
(c) iteratorSet()
(d) iterator()
Answer:

Option (d)

35.
Which of these methods can be used to move to next element in a collection?
(a) next()
(b) move()
(c) shuffle()
(d) hasNext()
Answer:

Option (a)

36.
Which of these iterators can be used only with List?
(a) Setiterator
(b) ListIterator
(c) Literator
(d) None of the mentioned
Answer:

Option (b)

37.
Which of these is a method of ListIterator used to obtain index of previous element?
(a) previous()
(b) previousIndex()
(c) back()
(d) goBack()
Answer:

Option (b)

38.
Which of these exceptions is thrown by remover() method?
(a) IOException
(b) SystemException
(c) ObjectNotFoundExeception
(d) IllegalStateException
Answer:

Option (d)

39.
What will be the output of the following Java program?
    import java.util.*;
    class Collection_iterators 
    {
        public static void main(String args[]) 
        {
            ListIterator a = list.listIterator();
                if(a.previousIndex()! = -1)
                    while(a.hasNext())
	                System.out.print(a.next() + " ");
                else
                   System.out.print("EMPTY");
        }
    }
(a) 0
(b) 1
(c) -1
(d) EMPTY
Answer:

Option (d)

40.
What will be the output of the following Java program?
    import java.util.*;
    class Collection_iterators 
    {
        public static void main(String args[]) 
        {
            LinkedList list = new LinkedList();
            list.add(new Integer(2));
            list.add(new Integer(8));
            list.add(new Integer(5));
            list.add(new Integer(1));
            Iterator i = list.iterator();
            Collections.reverse(list);
	    Collections.sort(list);
            while(i.hasNext())
	        System.out.print(i.next() + " ");
        }
    }
(a) 2 8 5 1
(b) 1 5 8 2
(c) 1 2 5 8
(d) 2 1 8 5
Answer:

Option (d)

Showing 31 to 30 out of 40 Questions