Course of Raku / Objects, I/O, and exceptions / Classes and objects / Methods / Exercises

Rectangle area

Problem

Define a class Rectangle with attributes width and height, a method area that returns the rectangle’s area, and a second method describe that returns the string area is <area> by calling its own area method through self.

Create a rectangle that is 3 wide and 4 high, and print its description.

Example

The program prints:

area is 12

Solution

See the solution

Course navigation

Solution: A reversed word   |   Solution: Rectangle area