Skip to content
Sharp

Core Java · interview question

Given a class with public fields in an e-commerce application, what is a likely issue?

Multiple choiceMediumchapter-3-curatedpremiumcore-javacode-reading-and-state-safety
Choose one answer
Answer and explanation

Correct answer

C. Fields can be accessed and modified freely, leading to potential invariants breakage.

Why

Having public fields allows any code to change the state of the object, making it easy to violate invariants and leading to inconsistent states.

Test yourself on Core Java

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

Start free test
All Core Java questions →