Creating Class Variables
When you create an object, it has its own version of all variables that are part of the object's class. Each object created from the Virus class of objects has its own version of the newSeconds, maxFileSize, and author variables. If you modified one of these variables in an object, it would not affect the same variable in another Virus object.
There are times when an attribute has more to do with an entire class of objects than a specific object itself. For example, if you wanted to keep track of how many Virus objects were being used in a program, it would not make sense to store this value repeatedly in each Virus object. Instead, you can use a class variable to store this kind of information. You can use this kind ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access