Skip to content
Sharp

Core Java · interview question

Which of the following code snippets demonstrates a weak object design in Java?

Multiple choiceMediumchapter-2-curatedpremiumcore-javacode-reading-and-refactoring-to-objects
Choose one answer
Answer and explanation

Correct answer

A. Class Product { public String name; public double price; }

Why

Making fields public breaks encapsulation and exposes internal data, making the class less flexible and more difficult to maintain.

Test yourself on Core Java

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

Start free test
All Core Java questions →