Java Type Wrapper Classes MCQ Questions and Answers

Study and learn Interview MCQ Questions and Answers on Java Type Wrapper Classes. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.

Go through Java Theory Notes on Type Wrappers before reading these objective questions.



1) What is a Type Wrapper or simply a Wrapper in Java?
A) A Wrapper class is an object version of Primitive Data Type
B) A Wrapper provides additional methods for ease of use
C) Wrapper types are useful for using with generic collections
D) All the above
Answer [=]
Answer[=]
2) Which primitive data types have wrapper classes available?
A) byte, short, int, long
B) float, double
C) boolean, char
D) All the above
Answer [=]
Answer[=]
3) Choose the correct mapping of Primitive Data Types and Wrapper Classes below?
A) boolean = Boolean, char = Character
B) byte = Byte, short = Short, int = Integer, long = Long
C) float = Float, double = Double
D) All the above
Answer [=]
Answer[=]
4) State TRUE or FALSE. Java primitive data types work faster compared to their Wrapper counter parts.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]
5) Which is the correct way of converting an int value to Integer in below Java code?
A)
Integer in = new Integer(9);
B)
Integer in = Integer.valueOf(9);
C)

 
Integer in = new Integer("9"); 
D) None of the above
Answer [=]
Answer[=]
6) Which is the Superclass of Wrapper types like Byte, Short, Integer, Long, Float and Double?
A) Math
B) System
C) Number
D) Enum
Answer [=]
Answer[=]
7) Which are the methods a Wrapper class object can use in Java?
A) byteValue(), shortValue, intValue(), longValue()
B) floatValue(), doubleValue()
C) booleanValue(), charValue()
D) All the above
Answer [=]
Answer[=]


 

8) Which is the superclass of wrapper classes like Boolean and Character?
A) Number
B) Wrapper
C) Object
D) Math
Answer [=]
Answer[=]
9) Are the sizes of float and Float same or different in Java?
A) Same
B) Different
C) -
D) -
Answer [=]
Answer[=]
10) Which are the constant fields available a Wrapper Class object in Java?
A) BYTES, SIZE
B) MAX_VALUE, MAX_EXPONENT
C) MIN_VALUE, MIN_EXPONENT
D) All the above
Answer [=]
Answer[=]
11) What is the output of the below Java code snippet on wrapper classes?
System.out.println(Byte.BYTES);
System.out.println(Character.BYTES);
System.out.println(Short.BYTES);
System.out.println(Integer.BYTES);
System.out.println(Long.BYTES);
System.out.println(Float.BYTES);
System.out.println(Double.BYTES);
A)
1
2
2
4
8
4
8
B)
1
4
2
4
8
4
8
C)
1
2
4
8
16
8
16
D) None of the above
Answer [=]
Answer[=]
12) Choose the correct way of creating a Float wrapper object in Java?
A)
Float pi = Float.valueOf(2.54f);
B)
Float pi = Float.valueOf(2.54);
C)
Float pi = new Float(2.54f);
D)
Float pi = new Float("2.54f");
Answer [=]
Answer[=]
13) Choose the correct way of comparing Wrapper objects in Java?
A)
float p1 = 10.45f;
float p2 = 5.2f;
if(Float.compare(p1, p2) == 1)
{
  System.out.println("10.45 > 5.2");
}
else
  System.out.println("No Biscuits");

//OUTPUT
10.45 > 5.2
B)
Float f1 = Float.valueOf("2.55");
Float f2 = Float.valueOf("4.5");

if(f1.compareTo(f2) == -1)
{
  System.out.println("2.55 < 4.5");
}
else
  System.out.println("No Tea");

//OUTPUT
2.55 < 4.5
C)
float t1 = 2.0f;
float t2 = 2.0f;
if(Float.compare(t1, t2) == 0)
{
  System.out.println("Float numbers are equal");
}

//OUTPUT
Float numbers are equal
D) All the above
Answer [=]
Answer[=]
14) Choose the correct statement about Character wrapper class in Java?
A) Character class has static methods toUpperCase(char), toLowerCase(char)
B) Character class has static methods isDigit(char), isLetter(char)
C) Character class has static method valueOf(char) to convert char to Character.
D) All the above
Answer [=]
Answer[=]


 

15) Choose the correct statement about Boolean wrapper class in Java?
A) Boolean class has static methods valueOf(boolean), valueOf("boolean") to convert boolean to Boolean object
B) Boolean class has static methods logicalAnd(boolean, boolean), logicalOr(boolean, boolean), logicalXor(boolean,boolean)
C) Boolean class has instance method equals() to check equality. compare() and compareTo() methods are also available
D) All the above
Answer [=]
Answer[=]
16) Which exception is thrown for trying to create Wrapper class objects with wrong number type?
A) ArithmeticException
B) NumberFormatException
C) IllegarArgumentException
D) TypeNotPresentException
Answer [=]
Answer[=]
17) What is the output of the below code snipper with Short class object?
Short sh = Short.valueOf(10);
System.out.println(sh);
A) 10
B) 0
C) Compiler error
D) None
Answer [=]
Answer[=]
18) Choose a correct statement about Type Casting using Wrapper class objects in Java?
A) You can not convert from Byte to Integer
B) You can not convert from Integer to Float
C) You can not convert from Integer to Long
D) All the above
Answer [=]
Answer[=]


Like or Share

Show some care. Like or Subscribe. [FB]...[Youtube]

C MCQ App by ExamTray 

Android APP

Java MCQ App by ExamTray 

Android APP
ALL MCQ App by ExamTray Android APP

Ad

 

Try Some Java Books

Book Price
1. Java - The Complete Reference  Check Price
2. Core Java: An Integrated Approach, Black Book Check Price
3. Java All-in-One for Dummies Check Price
4. OCP Java SE 8: Programmer II Check Price
5. Programming with Java Check Price
6. Head First Java Check Price

We may get some affiliate commission for the above purchases.