Java Multiple-Choice Quiz

Read short Java snippets about types, strings, constructors, and loops. The final questions cover overloaded methods, list operations, and what happens when two variables refer to the same object.

Ages 13+ · beginning Java learners and classroom review

Question 1 of 15

$100

Which primitive type belongs in the blank in ___ ready = true?

Ready to play?

Open at Step 3 with every question loaded. Play solo, host live, or customize your game.

Play & Customize Game

Questions by ladder level

Level 1 · Primitive types

Which primitive type belongs in the blank in ___ ready = true?

  1. boolean
  2. int
  3. char
  4. double
Show answer and explanation

Correct answer: A. boolean

The literal true has type boolean. Java uses this type for true and false values.

Question reference

Level 2 · Integer literals

The declaration long stars = 5_000_000_000L uses an L after the number. What does the L indicate?

  1. The literal has type double
  2. The variable can be assigned only once
  3. The literal has type long
  4. The value is rounded to fit an int
Show answer and explanation

Correct answer: C. The literal has type long

An L suffix gives the integer literal type long. Underscores separate groups of digits for readability.

Question reference

Level 3 · Integer arithmetic

What value does the Java expression -17 / 5 produce?

  1. -4
  2. -3
  3. 3
  4. -3.4
Show answer and explanation

Correct answer: B. -3

Both operands have integer type. Java integer division rounds the quotient toward zero, so the result is -3.

Question reference

Level 4 · String concatenation

What text does the Java expression "Tray " + 2 + 3 produce?

  1. 23 Tray
  2. Tray 5
  3. 5 Tray
  4. Tray 23
Show answer and explanation

Correct answer: D. Tray 23

The additions group from left to right. The first + joins the string and 2 to make Tray 2, then the second appends 3.

Question reference

Level 5 · Array indexing

An int[] named sizes contains {4, 7, 9} in that order. Which value does sizes[1] read?

  1. 4
  2. 7
  3. 9
  4. 1
Show answer and explanation

Correct answer: B. 7

Java gives the first array element index 0. Index 1 reads the second element, which is 7.

Question reference

Level 6 · String indexes

What string does "planet".substring(1, 4) return?

  1. lan
  2. plane
  3. lane
  4. pla
Show answer and explanation

Correct answer: A. lan

The substring begins at index 1 and ends before index 4. Those positions contain l, a, and n.

Question reference

Level 7 · Constructors and fields

Basket has a field int count and a constructor Basket(int count) { this.count = count; }. What value does new Basket(6).count read?

  1. Undefined
  2. 0
  3. 1
  4. 6
Show answer and explanation

Correct answer: D. 6

The right-hand count is the constructor parameter. The assignment stores its value, 6, in the new object's field this.count.

Question reference

Level 8 · A loop that tests at the end

Both value and total are ints, starting at 5 and 0. The program runs do { total += value; value--; } while (value < 3); What is total afterward?

  1. 4
  2. 0
  3. 5
  4. 9
Show answer and explanation

Correct answer: C. 5

The body runs once, adding 5 and reducing value to 4. Java then tests 4 < 3, so the loop ends.

Question reference

Level 9 · String equality

Both a and b are initialized by their own new String("mint") expression. In order, what are the results of a.equals(b) and a == b?

  1. true, false
  2. true, true
  3. false, true
  4. false, false
Show answer and explanation

Correct answer: A. true, false

The two strings contain the same text, so equals returns true. The new expressions create separate objects, so the reference comparison returns false.

Question reference

Level 10 · Continuing a loop

What is total after this Java snippet? int total = 0; for (int i = 1; i < 5; i++) { if (i == 2) continue; total += i; }

  1. 6
  2. 10
  3. 1
  4. 8
Show answer and explanation

Correct answer: D. 8

At i = 2, continue skips the addition and the loop proceeds with its update. The values added are 1, 3, and 4, giving 8.

Question reference

Level 11 · Character arithmetic

The UTF-16 code unit for 'A' has the numeric value 65. What is the type and value of the Java expression 'A' + 1?

  1. A String with the value A1
  2. A char with the value 'B'
  3. An int with the value 66
  4. An int with the value 65
Show answer and explanation

Correct answer: C. An int with the value 66

For this numeric addition, Java promotes the char operand to int. It adds 65 + 1 and produces the int value 66.

Question reference

Level 12 · Overloaded methods

One class declares pick(int n), which returns "int", and pick(double n), which returns "double". What does the call pick(3) return?

  1. double
  2. int
  3. 3
  4. 3.0
Show answer and explanation

Correct answer: B. int

The literal 3 has type int. The int overload is the more specific applicable choice for that argument.

Question reference

Level 13 · ArrayList removal

An ArrayList<Integer> named values contains [7, 3, 1]. What is in the list after values.remove(1)?

  1. [7, 3, 1]
  2. [7, 3]
  3. [3, 1]
  4. [7, 1]
Show answer and explanation

Correct answer: D. [7, 1]

The argument 1 is an int, so Java calls the overload that removes by index. Index 1 holds 3. Removing it leaves [7, 1].

Question reference

Level 14 · Overriding an instance method

Label declares an instance method text() that returns "plain". BrightLabel extends Label and overrides text() to return "bright". Given Label tag = new BrightLabel(), what does tag.text() return?

  1. bright
  2. plain
  3. BrightLabel
  4. null
Show answer and explanation

Correct answer: A. bright

Java looks up the overriding instance method using the actual object's class. The object is a BrightLabel, so its text method returns bright.

Question reference

Level 15 · Passing an array to a method

The method adjust(int[] values) first sets values[0] = 9 and then sets values = new int[]{4}. The caller starts with int[] boxes = {1, 2} and calls adjust(boxes). What does boxes contain afterward?

  1. [1, 2]
  2. [4]
  3. [9, 2]
  4. [9]
Show answer and explanation

Correct answer: C. [9, 2]

The parameter initially holds a copy of the reference to boxes, so the first assignment changes that array. Assigning a new array changes only the method's local parameter.

Question reference