Access Modifiers: Public vs Private

Learn about the public and private access modifiers and how they can be accessed from outside the class.

The public access modifier

The public access modifier allows code from both outside and inside the class to access the class’s methods and properties.

How to access a public property

In the following example, the class’s property and method are defined as public, so the code outside the class can directly interact with them.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy