This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
We call the variables inside a class, properties. Properties can accept values like strings, integers, and booleans (true/false values), like any other variable. We demonstrate how to use properties by adding an array for the recipe ingredients.
Properties
Variables within a class are called properties.
camelCase
The naming convention for properties is camelCase, like a camel, the “humps” are in the middle. The name starts with a lowercase letter, and all other words, start with a capital letter. For example, $ingredients or $dryIngredients.
Access Modifiers
Access modifiers allows us to control the access, or visibility, of our properties. These access modifiers are public, private, or protected. If declared using var, the property will be defined as public. When declaring a property, the visibility MUST be defined by an access modifier.
Public: Publicly accessible from anywhere, even from outside the scope of the class.
Private: Accessed within the class itself. It protects properties and methods from being accessed from outside the class.
Protected: Same as private, except by allowing child (sub) classes to access protected parent (super) properties and methods.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up