Sail E0 Webinar

MCQs

Total Questions : 105 | Page 6 of 11 pages
Question 51.


What is the output of this program?


import java.util.*;
class Bitset {
public static void main(String args[]) {
BitSet obj = new BitSet(5);
for (int i = 0; i < 5; ++i)
obj.set(i);
obj.clear(2);
System.out.print(obj.length() + " " + obj.size());
}
}
  1.    4 64
  2.    5 64
  3.    5 128
  4.    4 128
 Discuss Question
Answer: Option B. -> 5 64

obj.length() returns the length allotted to object obj at time of initialization and obj.size() 

returns the size of current object obj, each BitSet element is given 16 bits therefore the 

size is 4 * 16 = 64, whereas length is still 5.
Output:
$ javac Bitset.java
$ java Bitset
5 64


Question 52.

Which of these methods must be made static?


  1.    main()
  2.    delete()
  3.    run()
  4.    finalize()
 Discuss Question
Answer: Option A. -> main()

main() method must be declared static, main() method is called by Java’s run time system before 

any object of any class exists.


Question 53.

Which of these method is used to reduce the capacity of an ArrayList object?


  1.    trim()
  2.    trimSize()
  3.    trimTosize()
  4.    trimToSize()
 Discuss Question
Answer: Option D. -> trimToSize()

trimTosize() is used to reduce the size of the array that underlines an ArrayList object.

Question 54.

Which of these method is used to change an element in a LinkedList Object?


  1.    change()
  2.    set()
  3.    redo()
  4.    add()
 Discuss Question
Answer: Option C. -> redo()

 An element in a LinkedList object can be changed by first using get() to obtain the index 

or location of that object and the passing that location to method set() along with its new 

value.


Question 55.

Which of these class encapsulate the run time state of an object or an interface?


  1.    Class
  2.    Object
  3.    Runtime
  4.    System
 Discuss Question
Answer: Option A. -> Class

None.



Question 56.

Which of these method is used to change an element in a LinkedList Object?


  1.    change()
  2.    set()
  3.    redo()
  4.    add()
 Discuss Question
Answer: Option C. -> redo()

An element in a LinkedList object can be changed by first using get() to obtain the index 

or location of that object and the passing that location to method set() along with its new 

value.


Question 57.

Which of these method is used add an element and corresponding key to a map?


  1.    put()
  2.    set()
  3.    redo()
  4.    add()
 Discuss Question
Answer: Option A. -> put()

Maps revolve around two basic operations - get() and put(). to put a value into a map, 

use put(), specifying the key and the value. To obtain a value, call get() , passing the 

key as an argument. The value is returned,


Question 58.


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));
System.out.println(obj.elementAt(1));
}
}
  1.    0
  2.    3
  3.    2
  4.    5
 Discuss Question
Answer: Option C. -> 2

obj.elementAt(1) returns the value stored at index 1, which is 2.
Output:
$ javac vector.java
$ java vector
2


Question 59.


What is the output of this program?


import java.util.*;
class hashtable {
public static void main(String args[]) {
Hashtable obj = new Hashtable();
obj.put("A", new Integer(3));
obj.put("B", new Integer(2));
obj.put("C", new Integer(8));
System.out.print(obj.contains(new Integer(5)));
}
}
  1.    0
  2.    1
  3.    true
  4.    false
 Discuss Question
Answer: Option D. -> false

Hashtable object obj contains values 3, 2, 8 when obj.contains(new Integer(5)) is executed 

it searches for 5 in the hashtable since it is not present false is returned.

Output:
$ javac hashtable.java
$ java hashtable
false


Question 60.


What is the output of this program?


import java.util.*;
class Bitset {
public static void main(String args[]) {
BitSet obj = new BitSet(5);
for (int i = 0; i < 5; ++i)
obj.set(i);
obj.clear(2);
System.out.print(obj);
}
}
  1.    {0, 1, 3, 4}
  2.    {0, 1, 2, 4}
  3.    {0, 1, 2, 3, 4}
  4.    {0, 0, 0, 3, 4}
 Discuss Question
Answer: Option A. -> {0, 1, 3, 4}

 None.
Output:
$ javac Bitset.java
$ java Bitset
{0, 1, 3, 4}


Latest Videos

Latest Test Papers