Visibility modifiers
Let’s start with the most basic tool that object-oriented languages in general, and Java in particular, provide us with to enforce boundaries: visibility modifiers.
Visibility modifiers have been a topic in almost every entry-level job interview I have conducted in the last couple of years. I would ask the interviewee which visibility modifiers Java provides and what their differences are.
Most of the interviewees only list the public, protected, and private modifiers. Only a few of them know the package-private (or default) modifier. This is always a welcome opportunity for me to ask some questions about why such a visibility modifier would make sense in order to find out whether the interviewee can abstract from their previous knowledge.
So, why is the package-private modifier such an important modifier? Because it allows us to use Java packages to group classes into cohesive “modules.” Classes within such a module can access each...