When you post code, put code tags around your code to preserve the indenting.
Originally Posted by ccj64
When you create a new instance of a Car, the only thing that executes is this:
In that method, @@number_of_cars does not get reset to 0. Ruby parses the class definition once when it first encounters the class definition in your code. That's when 0 gets assigned to @@number_of_cars. Thereafter, when you create an instance of the class, that does not cause ruby to reparse the class definition.
@@number_of_cars += 1
When you create a new object of a class, the initialize() method in the class is called automatically if present.
2. I assume it is just 'convention' and the name 'initialize' that makes that method run each time a new instance of the object is created. Correct?