Wrapper Classes MCQ Practice

Question 1 of 10

A kiln logs unused glaze batches in a wrapper variable. What text does this Java code display?

Integer batches = 14;
System.out.print(batches);
  1. A. null
  2. B. 14
  3. C. Integer
  4. D. a compile-time error

Question 2 of 10

A tram unboxes leftover tokens before subtracting two. What text does this Java code display?

Integer tokens = 9;
int leftover = tokens;
System.out.print(leftover - 2);
  1. A. 9
  2. B. 11
  3. C. 7
  4. D. a compile-time error

Question 3 of 10

A marina kiosk reads a slip number from text. What text does this Java code display?

int slip = Integer.parseInt("26");
System.out.print(slip + 4);
  1. A. 30
  2. B. 264
  3. C. 26
  4. D. "26"

Question 4 of 10

A tide board parses a meter reading from text. What text does this Java code display?

double meters = Double.parseDouble("3.25");
System.out.print(meters + 1);
  1. A. 4
  2. B. 3.25
  3. C. 325
  4. D. 4.25

Question 5 of 10

A booth stamps a primitive ticket code into a wrapper parameter. What text does this Java code display?

public class Booth {
    public void stamp(Integer code) {
        System.out.print(code + 5);
    }
}

int raw = 8;
Booth b = new Booth();
b.stamp(raw);
  1. A. 8
  2. B. 13
  3. C. a compile-time error
  4. D. 5

Question 6 of 10

A lantern count is updated with arithmetic on a wrapper. What text does this Java code display?

Integer lanterns = 6;
lanterns = lanterns + 4;
System.out.print(lanterns);
  1. A. 10
  2. B. 6
  3. C. 4
  4. D. a compile-time error

Question 7 of 10

Two ferry counters start as aliases, then one wrapper variable is reassigned. What text does this Java code display?

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

Question 8 of 10

A harbor method reassigns its Integer parameter. What text does this Java code display?

public class Harbor {
    public void bump(Integer n) {
        n = n + 1;
    }
}

Integer slips = 4;
Harbor h = new Harbor();
h.bump(slips);
System.out.print(slips);
  1. A. 5
  2. B. 0
  3. C. a compile-time error
  4. D. 4

Question 9 of 10

A crate list autoboxes int values when they are added. What text does this Java code display?

import java.util.ArrayList;
ArrayList<Integer> crates = new ArrayList<Integer>();
crates.add(3);
crates.add(12);
int first = crates.get(0);
System.out.print(first + crates.get(1));
  1. A. 312
  2. B. 15
  3. C. 3
  4. D. a compile-time error because add expects Integer

Question 10 of 10

A weather kiosk labels each conversion. Using the table, which label is wrong?

Statement Student label
Integer p = 20; autoboxing
int k = p; unboxing
double x = Double.parseDouble("1.5"); autoboxing
Double d = 2.0; autoboxing
  1. A. the Integer p = 20; row
  2. B. the int k = p; row
  3. C. the parseDouble row
  4. D. the Double d = 2.0; row