Skip to content
Sharp

Core Java · interview question

What will be the value of 'totalPrice' after executing the following code? int unitPrice = 20; int quantity = 3; int totalPrice = unitPrice * quantity;?

Multiple choiceEasychapter-1-curatedpremiumcore-javaoperators-and-expressions
java
int unitPrice = 20;
int quantity = 3;
int totalPrice = unitPrice * quantity;
Choose one answer
Answer and explanation

Correct answer

A. 60

Why

The 'totalPrice' is calculated by multiplying 'unitPrice' by 'quantity'. Here, 20 multiplied by 3 equals 60.

Test yourself on Core Java

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

Start free test
All Core Java questions →