LearnFrenzy
Sign in Take a free test

Encapsulation · Encapsulation MCQ · Question 5

Making a property read-only Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

How do you make a property read-only to other classes?

  • A Make the field public final
  • B A private (preferably final) field with a getter and no setter Correct
  • C Mark the getter static
  • D Use protected
Correct Answer: Option B

A public final field also cannot be reassigned, but it exposes the representation.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links