Skip to content
Sharp

Core Java · interview question

Given the class Customer with a private field email, how can you provide access to this field in a controlled manner?

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

Correct answer

A. By creating public getter and setter methods.

Why

Creating public getter and setter methods allows controlled access to the email field. This approach maintains encapsulation, enabling validation or processing when getting or setting the field's value.

Test yourself on Core Java

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

Start free test
All Core Java questions →