Encapsulation

Java encapsulation: private fields, the four access levels, references that leak through getters and constructors, and composition against inheritance.

  • 8 cards
  • 5 questions
  • About 8 min
  • Intermediate to Advanced
Share

Encapsulation: keeping a class's data where only the class itself can change it, so its rules are enforced in one place. private is the keyword everyone types and the idea almost nobody finishes, because a private field handed out through a getter is not private any more. It covers private fields, the four access levels, a list that leaks through a getter, the same leak through a constructor, and composition against inheritance. It leaves out Java modules, which control access between whole libraries.

Contents

8 cardsnot started