250+ TOP MCQs on Java.lang Introduction and Answers

Java MCQs on java.lang library of Java Programming Language.

1. Which of these classes is not included in java.lang?
a) Byte
b) Integer
c) Array
d) Class

Answer: c
Clarification: Array class is a member of java.util.

2. Which of these is a process of converting a simple data type into a class?
a) type wrapping
b) type conversion
c) type casting
d) none of the Mentioned

Answer: a
Clarification: None.

3. Which of these is a super class of wrappers Double & Integer?
a) Long
b) Digits
c) Float
d) Number

Answer: d
Clarification: Number is an abstract class containing subclasses Double, Float, Byte, Short, Integer and Long.

4. Which of these is a wrapper for simple data type float?
a) float
b) double
c) Float
d) Double

Answer: c
Clarification: None.

5. Which of the following is a method of wrapper Float for converting the value of an object into byte?
a) bytevalue()
b) byte byteValue()
c) Bytevalue()
d) Byte Bytevalue()

Answer: b
Clarification: None.

6. Which of these methods is used to check for infinitely large and small values?
a) isInfinite()
b) isNaN()
c) Isinfinite()
d) IsNaN()

Answer: a
Clarification: isinfinite() method returns true is the value being tested is infinitely large or small in magnitude.

7. Which of the following package stores all the simple data types in java?
a) lang
b) java
c) util
d) java.packages

Answer: a
Clarification: None.

8. What will be the output of the following Java code?

  1.     class isinfinite_output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             Double d = new Double(1 / 0.);  
  6.             boolean x = d.isInfinite();
  7.             System.out.print(x);
  8.         }
  9.     }

a) 0
b) 1
c) true
d) false

Answer: c
Clarification: isInfinite() method returns true is the value being tested is infinitely large or small in magnitude. 1/0. is infinitely large in magnitude hence true is stored in x.
Output:

$ javac isinfinite_output.java
$ java isinfinite_output
true

9. What will be the output of the following Java code?

  1.     class isNaN_output 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             Double d = new Double(1 / 0.);  
  6.             boolean x = d.isNaN();
  7.             System.out.print(x);
  8.         }
  9.     }

a) 0
b) 1
c) true
d) false

Answer: d
Clarification: isisNaN() method returns true is the value being tested is a number. 1/0. is infinitely large in magnitude, which cannot be defined as a number hence false is stored in x.
Output:

$ javac isNaN_output.java
$ java isNaN_output
false

10. What will be the output of the following Java code?

  1.     class binary 
  2.     {
  3.          public static void main(String args[]) 
  4.          {
  5.              int num = 17;
  6.              System.out.print(Integer.toBinaryString(num));
  7.          }
  8.     }

a) 1001
b) 10011
c) 11011
d) 10001

Answer: d
Clarification: None.
output:

$ javac binary.java
$ java binary 
10001

Leave a Reply

Your email address will not be published. Required fields are marked *