Java Multiple Choice Questions & Answers on Java.lang package Boolean Wrapper Advance for Freshers

1. Which of these methods of Boolean wrapper returns boolean equivalent of an object.

a) getBool()
b) booleanValue()
c) getbooleanValue()
d) getboolValue()
Answer: b
2. Which of the following constant are defined in Boolean wrapper?

a) TRUE
b) FALSE
c) TYPE
d) All of the mentioned
Answer: d

Explanation: Boolean wrapper defines 3 constants – TRUE, FALSE & TYPE.
3. Which of these methods return string equivalent of Boolean object?

a) getString()
b) toString()
c) converString()
d) getStringObject()
Answer: b
4. Which of these methods is used to know whether a string contains “true”?

a) valueOf()
b) valueOfString()
c) getString()
d) None of the mentioned
Answer: a

Explanation: valueOf() returns true if the specified string contains “true” in lower or uppercase and false otherwise.
5. Which of these class have only one field?

a) Character
b) Boolean
c) Byte
d) void
Answer: d

Explanation: Void class has only one field – TYPE, ehich holds a reference to the Class object for type void. We do not create instance of this class.
6. What is the output of this program?
  1.     class Output {
  2.         public static void main(String args[]) {
  3.             String str = "true";
  4.             boolean x = Boolean.valueOf(str);
  5.             System.out.print(x);
  6.         }
  7.     }
a) true
b) flase
c) Compilation Error
d) Runtime Error
Answer: a

Explanation: valueOf() returns true if the specified string contains “true” in lower or uppercase and false otherwise.
7. What is the output of this program?
  1.     class Output {
  2.         public static void main(String args[]) {
  3.             String str = "true false true";
  4.             boolean x = Boolean.valueOf(str);
  5.             System.out.print(x);
  6.         }
  7.     }
a) true
b) false
c) Compilation Error
d) Runtime Error
Answer: b

Explanation: valueOf() returns true if the specified string contains “true” in lower or uppercase and false otherwise.
8. What is the output of this program?
  1.     class Output {
  2.         public static void main(String args[]) {
  3.             String str = "TRUE";
  4.             boolean x = Boolean.valueOf(str);
  5.             System.out.print(x);
  6.         }
  7.     }
a) true
b) flase
c) Compilation Error
d) Runtime Error
Answer: a

Explanation: valueOf() returns a Boolean instance representing the specified boolean value. If the specified boolean value is true, this method returns Boolean.TRUE; if it is false, this method returns Boolean.FALSE. If a new Boolean instance is not required, this method should generally be used in preference to the constructor Boolean(boolean), as this method is likely to yield significantly better space and time.
9. What is the output of this program?
  1.     class Output {
  2.         public static void main(String args[]) {
  3.      String str = "true false";
  4.             boolean x = Boolean.parseBoolean(str);
  5.             System.out.print(x);
  6.         }
  7.     }
a) true
b) false
c) System Dependent
d) Compilation Error
Answer: b

Explanation: parseBoolean() Parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string “true”.
Example: Boolean.parseBoolean(“True”) returns true.
Example: Boolean.parseBoolean(“yes”) returns false.
10. What is the output of this program?
  1.     class Output {
  2.         public static void main(String args[]) {
  3.     String x = Boolean.toString(false);
  4.         }
  5.     }
a) true
b) false
c) System Dependent
d) Compilation Error
Answer: b

Explanation: toString() Returns a String object representing the specified boolean. If the specified boolean is true, then the string “true” will be returned, otherwise the string “false” will be returned

Related

Data Structures Multiple Choice Questions and Answers on Stack using Array

1. Which of the following real world scenarios would you associate with a stack data structure? a) piling up of chairs one above the otherb) people standing in a line to be serviced at a counterc) ...

Data Structures Multiple Choice Questions and Answers on Inorder Traversal

1. For the tree below, write the in-order traversal. a) 2, 7, 2, 6, 5, 11, 5, 9, 4b) 2, 7, 5, 2, 6, 9, 5, 11, 4c) 2, 5, 11, 6, 7, 4, 9, 5, 2d) 2, 7, 5, 6, 11, 2, 5, 4, 9 Answer: d Explanation: In...

Data Structures Multiple Choice Questions and Answers on Circular Linked List

1. What differentiates a circular linked list from a normal linked list? a) You cannot have the ‘next’ pointer point to null in a circular linked listb) It is faster to traverse the circular linked...

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