Wrapper Classes MCQ Practice

Question 1 of 10

An orchard kiosk stores a crate mass in a wrapper. What text does this Java code display?

Double kilos = 8.5;
System.out.print(kilos);
  1. A. 8.5
  2. B. 8
  3. C. a compile-time error
  4. D. null

Question 2 of 10

A canyon gauge unboxes a depth before doubling. What text does this Java code display?

Double depth = 2.0;
double meters = depth;
System.out.print(meters * 2);
  1. A. 2.0
  2. B. 22.0
  3. C. a compile-time error
  4. D. 4.0

Question 3 of 10

A radio tower parses a channel code, then boxes it. What text does this Java code display?

int code = Integer.parseInt("7");
Integer wrapped = code;
System.out.print(wrapped);
  1. A. 77
  2. B. 7
  3. C. a compile-time error
  4. D. "7"

Question 4 of 10

A rain barrel parser boxes a parsed primitive. What text does this Java code display?

Double rain = Double.parseDouble("0.75");
System.out.print(rain);
  1. A. 75
  2. B. 0
  3. C. 0.75
  4. D. a compile-time error

Question 5 of 10

A lab method expects a Double and halves it. What text does this Java code display?

public class Lab {
    public double half(Double n) {
        return n / 2;
    }
}

Lab lab = new Lab();
System.out.print(lab.half(10.0));
  1. A. 5.0
  2. B. 10.0
  3. C. 2.0
  4. D. a compile-time error because half expects Double

Question 6 of 10

A skip counter is unboxed from a null wrapper. What happens when this Java code runs?

Integer skip = null;
int n = skip;
System.out.print(n);
  1. A. 0 is displayed
  2. B. null is displayed
  3. C. a NullPointerException occurs
  4. D. a compile-time error occurs

Question 7 of 10

Two orchard counts start equal, then one wrapper is replaced. What text does this Java code display?

Integer a = 4;
Integer b = 4;
a = a + 1;
System.out.print(a + "," + b);
  1. A. 5,5
  2. B. 5,4
  3. C. 4,4
  4. D. 4,5

Question 8 of 10

A dock method returns a boxed primitive. What text does this Java code display?

public class Dock {
    public Integer wrap(int n) {
        return n;
    }
}

Dock d = new Dock();
int raw = 15;
Integer box = d.wrap(raw);
System.out.print(box);
  1. A. a compile-time error
  2. B. 0
  3. C. 1515
  4. D. 15

Question 9 of 10

A tag list autoboxes a copy of a primitive. What text does this Java code display?

import java.util.ArrayList;
ArrayList<Integer> tags = new ArrayList<Integer>();
int seed = 6;
tags.add(seed);
seed = 1;
System.out.print(tags.get(0));
  1. A. 6
  2. B. 1
  3. C. 7
  4. D. a compile-time error

Question 10 of 10

A catalog clerk compares packages. Using the table, which statement is true?

Type Package Import required?
Integer java.lang no
Double java.lang no
ArrayList java.util yes
  1. A. Integer must be imported from java.util
  2. B. Double is mutable so its stored number can be changed in place
  3. C. Integer and Double live in java.lang, so they compile without an import
  4. D. ArrayList is in java.lang with Integer