Skip to content
Sharp

Core Java · interview question

Which statement correctly calculates the total number of items in a shopping cart?

Multiple choiceMediumchapter-1-curatedpremiumcore-javaloops-and-iteration
Choose one answer
Answer and explanation

Correct answer

C. TotalItems = cart.length;

Why

In Java, the length of an array is accessed using 'array.length'. This gives the total number of elements in the array, which represents the number of items in the shopping cart.

Test yourself on Core Java

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

Start free test
All Core Java questions →