Deviopath › Go

Rectangle Methods

Medium · Methods

A method is a function with a receiver: func (r Rect) Area() int. Value receivers are fine when the method only reads fields.

Rect is already defined. Write methods Area() and Perimeter() on Rect. RunRect(w, h) is already written and returns [area, perimeter].

Next: Shape Area