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

Triple as a method

Problem

Now solve the same task as a method. Define a class Number with an attribute n, and a method triple that returns three times n. Create a Number with n equal to 7, and print the result of calling triple on it.

Example

The program prints:

21

Solution

See the solution

Course navigation

Solution: Triple as a subroutine   |   Solution: Triple as a method