Skip to content
Sharp

Core Java · interview question

In a simple e-commerce application, you have a variable for the price of a product. Which one of the following variable declarations is correct for a product price?

Multiple choiceEasychapter-1-curatedpremiumcore-javacode-reading-and-debugging
Choose one answer
Answer and explanation

Correct answer

C. Double price = 19.99;

Why

The correct data type for storing decimal values such as prices is 'double'. Using 'int' or 'String' would not correctly represent decimal numbers.

Test yourself on Core Java

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

Start free test
All Core Java questions →