Visibility Modifiers
Learn what visibility modifiers are and how you can leverage them to write clean and maintainable code.
We'll cover the following
Let’s start with the most basic tool that Java provides us for enforcing boundaries: visibility modifiers.
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 the differences between them are.
Most of the interviewees only list the public, protected, and private modifiers. Almost none knows 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 if the interviewee could abstract from their previous knowledge.
So, why is the package-private modifier such an important modifier?
Get hands-on with 1400+ tech skills courses.