Java Multiple Choice Questions & Answers on Java.util package BitSet & Date class for Freshers

1. Which of these class object has architecture similar to that of array?

a) Bitset
b) Map
c) Hashtable
d) All if the mentioned
Answer: a

Explanation: Bitset class creates a special type of array that holds bit values. This array can increase in size as needed.
2. Which of these method is used to make a bit zero specified by the index?

a) put()
b) set()
c) remove()
d) clear()
Answer: d
3. Which of these method is used to calculate number of bits required to hold the BitSet object?

a) size()
b) length()
c) indexes()
d) numberofBits()
Answer: b
4. Which of these is a method of class Date which is used to search weather object contains a date before the specified date?

a) after()
b) contains()
c) before()
d) compareTo()
Answer: c

Explanation: before() returns true if the invoking Date object contains a date that is earlier than one specified by date, otherwise it returns false.
5. Which of these methods is used to retrieve elements in BitSet object at specific location?

a) get()
b) Elementat()
c) ElementAt()
d) getProperty()
Answer: a
6. What is the output of this program?
  1.     import java.util.*;
  2.     class Bitset {
  3.         public static void main(String args[]) {
  4.             BitSet obj = new BitSet(5);
  5.             for (int i = 0; i < 5; ++i)
  6.                 obj.set(i);
  7.             obj.clear(2);
  8.             System.out.print(obj);
  9.         }
  10.     }
a) {0, 1, 3, 4}
b) {0, 1, 2, 4}
c) {0, 1, 2, 3, 4}
d) {0, 0, 0, 3, 4}
Answer: a
7. What is the output of this program?
  1.     import java.util.*;
  2.     class Bitset {
  3.         public static void main(String args[]) {
  4.             BitSet obj = new BitSet(5);
  5.             for (int i = 0; i < 5; ++i)
  6.                 obj.set(i);
  7.             obj.clear(2);
  8.             System.out.print(obj.length() + " " + obj.size());
  9.         }
  10.     }
a) 4 64
b) 5 64
c) 5 128
d) 4 128
Answer: b

Explanation: 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.
8. What is the output of this program?
  1.     import java.util.*;
  2.     class Bitset {
  3.         public static void main(String args[]) {
  4.             BitSet obj = new BitSet(5);
  5.             for (int i = 0; i < 5; ++i)
  6.                 obj.set(i);
  7.             System.out.print(obj.get(3));
  8.         }
  9.     }
a) 2
b) 3
c) 4
d) 5
Answer: a
9. What is the output of this program?
  1.     import java.util.*;
  2.     class date {
  3.         public static void main(String args[]) {
  4.             Date obj = new Date();
  5.             System.out.print(obj);
  6.         }
  7.     }
a) Prints Present Date
b) Runtime Error
c) Any Garbage Value
d) Prints Present Time & Date
Answer: d
10. What is the output of this program?
  1.     import java.util.*;
  2.     class Bitset {
  3.         public static void main(String args[]) {
  4.             BitSet obj1 = new BitSet(5);
  5.             BitSet obj2 = new BitSet(10);
  6.             for (int i = 0; i < 5; ++i)
  7.                 obj1.set(i);
  8.             for (int i = 3; i < 13; ++i)
  9.                 obj2.set(i);
  10.             obj1.and(obj2);
  11.             System.out.print(obj1);
  12.         }
  13.     }
a) {0, 1}
b) {2, 4}
c) {3, 4}
d) {3, 4, 5}
Answer: c

Explanation: obj1.and(obj2) returns an BitSet object which contains elements common to both the object obj1 and obj2 and stores this BitSet in invoking object that is obj1. Hence obj1 contains 3 & 4.

Related

Multiple Choice Questions 6771796706710512943

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item