MCQs
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.
Output:
$ javac vector.java
$ java vector
true
obj.toString returns String equivalent of the hashtable, which can also be obtained by
simply writing System.out.print(obj); as print system automatically coverts the obj to
string equivalent.
Output:
$ javac hashtable.java
$ java hashtable
{A=3, C=8, B=2}
None.
Output:
$ javac date.java
$ java date
Tue Jun 11 11:29:57 PDT 2013
None.
Output:
$ javac Output.java
$ java Output
2
What is the output of this program?
class access{
static int x;
void increment(){
x++;
}
}
class static_use {
public static void main(String args[])
{
access obj1 = new access();
access obj2 = new access();
obj1.x = 0;
obj1.increment();
obj2.increment();
System.out.println(obj1.x + " " + obj2.x);
}
}
All objects of class share same static variable, all the objects share same copy of static members,
obj1.x and obj2.x refer to same element of class which has been incremented twice and its value is 2.
output:
$ javac static_use.java
$ java static_use
2 2
Arrays.sort(array) method sorts the array into 1,2,3,4,5.
Output:
$ javac Array.java
$ java Array
12345
None.
Output:
$ javac Linkedlist.java
$ java Linkedlist
[B, C]
None.
Output:
$ javac Output.java
$ java Output
3
keySet() method returns a set containing all the keys used in the invoking map. Here
keys are characters A, B & C. 1, 2, 3 are the values given to these keys.
Output:
$ javac Maps.java
$ java Maps
[A, B, C]
What is the output of this program?
import java.util.*;
class vector {
public static void main(String args[]) {
Vector obj = new Vector(4,2);
obj.addElement(new Integer(3));
obj.addElement(new Integer(2));
obj.addElement(new Integer(5));
obj.insertElementAt(new Integer(8), 2);
System.out.println(obj);
}
}
None.
Output:
$ javac vector.java
$ java vector
[3, 2, 8, 6]