Procedural programming approaches an application by defining the steps that need to be taken. Conversely, object-oriented programming focuses on the data being used by an application. With this approach, a class needs to represent the application’s data in terms of both the information that needs to be stored and the sorts of tasks that will be done with the data. Information can be represented in variables (called attributes or properties when in classes) and functions (called methods). As a theoretical but approachable example, think of a person: a person has attributes—name, age, etc.—and methods—eating, sleeping, and so forth.
A basic class definition begins with the keyword
class, followed by the name of the class. The code ...