Skip to content
Sharp

Core Java · interview question

In Java, what is the best way to declare a variable for a product's name?

Multiple choiceMediumchapter-1-curatedpremiumcore-javavariables-and-data-types
Choose one answer
Answer and explanation

Correct answer

D. String productName;

Why

The 'String' type is used for sequences of characters, making it ideal for storing product names. Arrays of 'char' are less convenient, and 'int' or 'double' are for numeric values.

Test yourself on Core Java

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

Start free test
All Core Java questions →