Courseiva
Primitives, Strings and OperatorseasyMultiple ChoiceObjective-mapped

1Z0-811 Primitives, Strings and Operators Practice Question

A developer writes: int a = 9; int b = 2; double result = a / b; System.out.println(result); What is the output?

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

4.0

(4.0). In Java, when dividing two integers, the result is integer division, which truncates the fractional part. So 9 / 2 yields 4 (int). This int value is then assigned to a double variable, resulting in 4.0. Option A (4) would be the result of printing an int, but since result is double, it prints 4.0. Option C is incorrect because the code compiles fine. Option D is incorrect because 4.5 would require at least one operand to be double (e.g., a / (double)b).

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • 4

    Why it's wrong here

    Printing double shows decimal.

  • 4.0

    Why this is correct

    Integer division yields 4, stored as double.

  • Compilation error

    Why it's wrong here

    Code compiles fine.

  • 4.5

    Why it's wrong here

    Would need one operand to be double.

About these practice questions

Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on 1Z0-811

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. Given: int a = 9; int b = 2; double c = a / b; System.out.println(c); What is the output?

easy
  • A.4.5
  • B.4.0
  • C.0.0
  • D.4

Why B: The expression `a / b` performs integer division because both operands are `int`. The result of `9 / 2` is `4` (the fractional part is truncated). This integer result is then implicitly widened to `double` when assigned to `c`, producing `4.0`. Therefore, the output is `4.0`.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.