Skip to content
Sharp

Core Java · interview question

Why can using public fields in a Java class become risky in production code?

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

Correct answer

D. The fields can be accessed and modified without any control

Why

Using public fields allows direct access and modification, which bypasses encapsulation and control mechanisms, leading to potential misuse and state corruption.

Test yourself on Core Java

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

Start free test
All Core Java questions →