Chapter 3: Classes and attributes

Instance attributes

face Josiah Wang

As mentioned, a class is like an outline of the object that you will create.

A class instance can have multiple instance variables, or instance attributes.

Instance attributes describe the properties (what an object has) and the states of the object. For example, a person can have an id, name, age, nationality, etc. You can access an object’s properties with a dot operator, e.g. lecturer.age. You can informally read this as "the lecturer's age".

Below is a class diagram that shows the attributes of a Person class instance. Class diagrams are part of the Unified Modelling Language (UML) for designing programs in an object-oriented way.

Class diagram