Private Methods
This lesson briefs on why and how to make methods private.
Remember how we said that instance variables store data that is “private” to the object?
▶️ Instance variables are only made accessible to the outside world (we say “it is exposed”) if we add attribute accessors to the class.
In the same way, classes sometimes want to keep certain methods private: methods that aren’t supposed to be called from outside of the object. Only the object itself is supposed to use them internally, from other methods.
Imagine I am an instance of a class ItalianRestaurant
, and I have a method
...
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy