Java Questions and Answers Part-20

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

Answer: c
Explanation: 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
Explanation: type wrapping

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

Answer: d
Explanation: 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
Explanation: Float

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
Explanation: byte byteValue()

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
Explanation: 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
Explanation: lang

8. What will be the output of the following Java code?
class isinfinite_output
{
public static void main(String args[])
{
Double d = new Double(1 / 0.);
boolean x = d.isInfinite();
System.out.print(x);
}
}
a) 0
b) 1
c) true
d) false

Answer: c
Explanation: 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:
true

9. What will be the output of the following Java code?
class isNaN_output
{
public static void main(String args[])
{
Double d = new Double(1 / 0.);
boolean x = d.isNaN();
System.out.print(x);
}
}
a) 0
b) 1
c) true
d) false

Answer: d
Explanation: 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:
false

10. What will be the output of the following Java code?
class binary
{
public static void main(String args[])
{
int num = 17;
System.out.print(Integer.toBinaryString(num));
}
}
a) 1001
b) 10011
c) 11011
d) 10001

Answer: d
Explanation:
output:
10001