MCQs
What is the output of this 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);
while(i.hasNext())
System.out.print(i.next() + " ");
}
}
Collections.reverse(list) reverses the given list, the list was 2->8->5->1 after
firstly elements 3, 2, 5 are entered in the vector obj, but when obj.removeAll(obj);
None.
This is an example of the islands of isolated objects. By the time line 11 has run, the objects
instantiated in lines 6 and 7 are referring to each other, but no live thread can reach either of them.
class A is an abstract class, it contains a abstract function display(), the full implementation of
display() method is given in its subclass B, Both the display functions are the same. Prototype
of display() is defined in class A and its implementation is given in class B.
output:
$ javac Abstract_demo.java
$ java Abstract_demo
2
None.
output:
$ javac Output.java
$ java Output
true
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 rue.
Output:
$ javac vector.java
$ java vector
true
What is the output of this 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();
while(i.hasNext())
System.out.print(i.next() + " ");
}
}
None.
Output:
$ javac Collection_Algos.java
$ java Collection_Algos
2 8 5 1
LinkedHashMap is the collection class used for caching purposes. FIFO is another way
to indicate caching behavior. To retrieve LinkedHashMap elements in cached order, use
the values() method and iterate over the resultant collection.
array was containing 5,4,3,2,1 but when method Arrays.fill(array, 1, 4, 8) is
called it fills the index location starting with 1 to 4 by value 8 hence array
becomes 5,8,8,8,1.
Output:
$ javac Array.java
$ java Array
58881