Challenge: Implement Inheritance Hierarchy
A coding challenge based on the concepts covered in this chapter.
We'll cover the following...
Problem statement
Let’s modify RailwayVehicle
. In addition to reporting the distance that it advances, let’s have it also make sounds. To keep the output short, let’s print the sounds per 100 kilometers:
class RailwayVehicle {
void advance(size_t kilometers) {
writefln("The vehicle is advancing %s kilometers", kilometers);
foreach (i; 0 .. kilometers
...