As the name suggests, access modifiers help to restrict the scope of a class, constructor, variable, or method. Let's take a look at the different access modifiers and see how to impact our logic.
Let's go back to our class and analyze the code a little bit more in depth. The first line in our code is the definition of our class:
public class MovieSelector {
}
In this line of code, you have three parts:
- public: Our access modifier
- class: Because we define a class
- MovieSelector: The name of the class
The first part is the most important in this chapter.
The access modifier allows you to define the visibility of your classes, variables, or methods. I will give you an overview of the different access modifiers and what they mean for the visibility when you call the class or method in other classes, subclasses, or outside the application.
Let's take...