Java Autoboxing and Unboxing MCQ Questions and Answers

Study and learn Interview MCQ Questions and Answers on Java Autoboxing and Unboxing. 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 Wrapper and Autoboxing before reading these objective questions.



1) Choose a correct statement about Autoboxing in Java?
A) Boxing is the process of converting a primitive data to its equivalent Wrapper class type
B) Unboxing is the process of converting a Wrapper class object to its equivalent primitive data type
C) Autoboxing is the process of converting Primitive data type to Wrapper Object type automatically. Auto-Unboxing is the process of converting Wrapper type object to Primitive type automatically.
D) All the above
Answer [=]
Answer[=]
2) Which does autoboxing or unboxing in Java?
A) Compiler
B) Runtime
C) Third party tools
D) None
Answer [=]
Answer[=]
3) Autoboxing or unboxing involves replacement of Wrapper objects with Primitives and vice versa. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]
4) Which Java version introduced the feature Autoboxing and Unboxing?
A) Java 4
B) Java 5
C) Java 6
D) Java 7
Answer [=]
Answer[=]
5) What is the need for Autoboxing and Unboxing in Java?
A) Reduces code to be written by developers to convert from Wrapper to Primitive vice versa
B) Compile time is reduced due to fixed methods followed to automatically convert Objects and Primitives
C) Auto-unboxing improves memory efficiency by converting Wrapper to Primitive and process when object version is not needed
D) All the above
Answer [=]
Answer[=]
6) Choose the right statement which does autoboxing in Java?
A)
Integer temperature1 = 100;
B)
int temperature2 = 101;
C)
Integer temperature1 = 100;
int temperature2 = 101;
D) All the above
Answer [=]
Answer[=]
7) Choose the correct way of autoboxing Primitives to Wrapper objects below?
A)
Float f1 = 1.0f;
B)
Boolean bull = false;
C)
Character ch = 'a';
D) All the above
Answer [=]
Answer[=]


 

8) Does the below Java code undergoes autoboxing correctly?
long weight = 10;
Long wei = weight;
System.out.println(ch.SIZE);
A) Yes
B) No
C) -
D) -
Answer [=]
Answer[=]
9) Auto-boxing or Auto-unboxing involves assignment (not always) in Java. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]
10) Auto-boxing or Auto-unboxing does not work inside static methods in Java. State TRUE or FALSE
A) FALSE
B) TRUE
C) -
D) -
Answer [=]
Answer[=]
11) What is the output of the below java code with autoboxing?
public class AutoBoxingTest2
{
  static void show(int reading)
  {
    System.out.println("Reading: " + reading);
  }
  public static void main(String[] args)
  {
    Integer a = Integer.valueOf(10);
    show(a);
  }
}
A) Reading: 0
B) Reading: 10
C) Compiler error
D) None
Answer [=]
Answer[=]
12) Which is faster Auto-boxing or Auto-unboxing?
A) Auto-boxing
B) Auto-unboxing
C) -
D) -
Answer [=]
Answer[=]
13) Does autoboxing work with creation of an Array in Java?
A) Yes
B) No
C) -
D) -
Answer [=]
Answer[=]
14) Autoboxing or Auto-unboxing works with ___ in Java.
A) Loops, Switch statements
B) Ternary Operator
C) IF ELSE statements
D) All the above
Answer [=]
Answer[=]


 

15) Autoboxing or Auto-unboxing is ___ in Java.
A) Implicit
B) Explicit
C) -
D) -
Answer [=]
Answer[=]
16) Choose the correct code that does auto-unboxing?
A)
Character ch = 'S';
switch(ch)
{
  case 'S': System.out.println("OK"); break;
  case 'p': break;
}

//OUTPUT
OK
B)
Integer t = 90;
int abc = ++t;
System.out.println(abc);

//OUTPUT
91
C)
int b =  10;
Integer c = 20;
if(b < c)
{
  System.out.println("LESS");
}

//OUTPUT
LESS
D) All the above
Answer [=]
Answer[=]
17) What is the output of the below Java code snippet that use Autoboxing and Unboxing?
public class AutoUnboxingTest1
{
  public static void main(String[] args)
  {
    int apple1 = 10;
    Integer apple2 = 10;
    if(apple1 == apple2)
      System.out.println("apple1=apple2");
    else
      System.out.println("apple1!=apple2");
  }
}
A)
apple1=apple2
B)
apple1!=apple2
C) Compiler error
D) Non
Answer [=]
Answer[=]
18) Autoboxing and unboxing in Java language saves the programmer from errors and extra lines of code. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]
19) What is the output of the below Java code with Autoboxing and unboxing?
float f1 = 10.0f;
Float f2 = Float.valueOf(10);
if(f1 == f2)
  System.out.println("FLOATs are equal.");
else
  System.out.println("FLOATs are not equal.");
A) FLOATs are equal.
B) FLOATs are not equal.
C) Compiler error
D) None
Answer [=]
Answer[=]
20) Choose the correct statement with auto-unboxing in Java?
A)
Short s1 = (short)30;
short s2 = s1;
B)
Boolean b1 = Boolean.valueOf(true);
boolean b2 = b1;
C)
Character ch1 = Character.valueOf('a');
char ch2 = ch1;
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.