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

Describe a class

Problem

Define a base class Animal and a class Dog that inherits from it. Then print the name of the Dog class, and on the next line the number of types in its inheritance chain (use .^mro and count its elements). Finally, on a third line, print whether a class named Cat appears anywhere in that chain.

Example

The program prints:

Dog
4
False

Solution

See the solution

Course navigation

Quiz — Introspection   |   Solution: Describe a class