Skip to main content

Section 13.6 Accessing Properties

Our constructor so far can only create rectangles with width and height of 1. Ideally, we would like to set the rectangle’s dimensions when we create the point, and we will see how to do that in Section 13.7. But for now, let’s see how to directly access and modify a rectangle’s state.
To access an object’s state variables, you write the object variable, a dot, and the attribute you wish to access. If it’s on the left hand side of an assignment, the property gets updated. (You may wish to use codelens to see this code execute step by step and see how the object’s attributes are modified.)
While it is possible to access an object’s attributes directly, it is not encouraged, and it is certainly a lot of work to go through to initialize a point to a desired coordinate. There must be a better way.