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

A formula on the class

Problem

A class method can take parameters, just like any other method. Define a class Geometry with a class method circle-area that takes a radius and returns the area of a circle (use π or pi), rounded an integer. The formula belongs to the class as a whole — there is no individual circle object involved. Call the method on the class with a radius of 10 and print the result.

Example

The program prints:

314

Solution

See the solution

Course navigation

Class methods   |   Solution: A formula on the class