RSRobince Studio

Encapsulation

Encapsulation means hiding internal data so it can only change in controlled ways.

A field starting with # is private. It cannot be read or changed from outside the class.

  • Private fields keep internal state safe
  • A getter exposes a safe, read-only view
  • Methods control how the data changes
Try it yourself

Loading editor…