MCQs
None.
Output:
$ javac hashtable.java
$ java hashtable
{C=8, B=2}
None.
Output:
$ javac Bitset.java
$ java Bitset
2
obj is an object of class ArrayList hence it is an dynamic array which can increase and
decrease its size. obj.add("X") adds to the array element X and obj.add(1,"X") adds
element x at index position 1 in the list, Hence obj.add(1,"D") stores D at index position
1 of obj and shifts the previous value stored at that position by 1.
Output:
$ javac Arraylist.java
$ java Arraylist
[A, D, B, C]
What is the output of this program?
class access{
public int x;
static int y;
void cal(int a, int b){
x += a ;
y += b;
}
}
class static_specifier {
public static void main(String args[])
{
access obj1 = new access();
access obj2 = new access();
obj1.x = 0;
obj1.y = 0;
obj1.cal(1, 2);
obj2.x = 0;
obj2.cal(2, 3);
System.out.println(obj1.x + " " + obj2.y);
}
}
None.
output:
$ javac static_specifier.java
$ java static_specifier
1 5
obj.addFirst("D") method is used to add 'D' to the start of a LinkedList object obj.
Output:
$ javac Linkedlist.java
$ java Linkedlist
[D, A, B, C]
clone() method of object class is used to generate duplicate copy of the object on which it
is called. Copy of obj1 is generated and stored in obj2.
Output:
$ javac Output.java
$ java Output
1 2 1 2
None.
Output:
$ javac Maps.java
$ java Maps
{A=1, B=2, C=3}
None.
Output:
$ javac vector.java
$ java vector
4
obj1 and obj2 are an object of class ArrayList hence it is a dynamic array which can
increase and decrease its size. obj.add("X") adds to the array element X and obj.add
(1,"X") adds element x at index position 1 in the list, Both the objects obj1 and obj2
contain same elements i:e A & B thus obj1.equals(obj2) method returns true.
Output:
$ javac Arraylist.java
$ java Arraylist
true
None.
Output:
$ javac hashtable.java
$ java hashtable
0