Defining Classes: Attributes and Methods
In the last article, we learned that a class is a blueprint and an object is the instance we create from it. We used the init() method to set up the initial data, or attributes, of an object.
In the last article, we learned that a class is a blueprint and an object is the instance we create from it. We used the init() method to set up the initial data, or attributes, of an object.
We've learned how to define methods—functions inside a class—that give our objects behavior. So far, all the methods we've created have been instance methods, which operate on a specific instance of a class.
We've created a Car class that holds data (attributes) and has behaviors (methods). But what happens when we try to print() one of our Car objects directly?