Skip to content
Sharp

Core Java · interview question

What will be printed by the following code snippet?

Multiple choiceMediumchapter-1-curatedpremiumcore-javacode-reading-and-debugging
java
int cartTotal = 10;
cartTotal += 5;
System.out.println(cartTotal);
Choose one answer
Answer and explanation

Correct answer

C. 15

Why

The 'cartTotal' is incremented by 5 after being initialized to 10, resulting in a final value of 15 being printed.

Test yourself on Core Java

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

Start free test
All Core Java questions →