Skip to main content

Section 13.9 Objects as Arguments and Parameters

You can pass an object as an argument in the usual way. Here is a function called averageArea involving our new Rectangle objects. The job of this function is to figure out the average area of two rectangles.
averageArea takes two rectangles and returns their average area. Note that averageArea is not a method of the Rectangle class. You can see this by looking at the indentation pattern. It is not inside the class definition. The other way we can determine that averageArea is not a method of Rectangle is that self is not included as a formal parameter. In addition, we do not invoke averageArea using the dot notation.