Skip to content
Sharp

Core Java · interview question

What is the outcome of the following code? int quantity = 5; quantity += 3; quantity -= 2;?

Multiple choiceMediumchapter-1-curatedpremiumcore-javaoperators-and-expressions
java
int quantity = 5;
quantity += 3;
quantity -= 2;
Choose one answer
Answer and explanation

Correct answer

B. 6

Why

First, 'quantity' is increased by 3, resulting in 8. Then, it's decreased by 2, leading to a final value of 6.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →