Course of Raku / Objects, I/O, and exceptions / Classes and objects / Inheritance / Exercises
An inherited attribute
Problem
Define a base class Vehicle with an attribute
wheels. Then define two classes that inherit from it:
Bike, which comes with 2 wheels, and
Car, which comes with 4.
Create a Bike and a Car, and print the
number of wheels each of them has.
Example
The program prints:
2
4Solution
Course navigation
← Solution: A shape and a square | Solution: An inherited attribute →