Java access modifiers: which to choose when, and why

Photo by Michael Dziedzic on Unsplash

On one of those question-and-answer websites, someone asked: What is the point of Java access modifiers if you can always just change them? It’s a question that crossed my mind when I was starting to learn Java years ago.

The student learns what the access modifiers are, and their semantics. And hopefully the student is given some guidance as to how to choose a modifier in…