Exercises
With interfaces and abstract classes, we can improve our application structure even further! Take a look at the following exercises to test your knowledge:
- Dinosaurs, no matter the exact species, have common behaviors such as eating and moving. Define an interface that encapsulates these behaviors, come up with a logical name for it, and implement it in the
Dinosaurclass. - Our park uses different types of vehicles for different purposes. Design an
abstractclass calledVehicleand derive concrete classes such asJeepandHelicopterfrom it. - Modify the
Vehicleclass so that it includes anabstractmethod calledtravel()that provides different implementations in its subclasses. - Make our
Dinosaurclass sortable by implementing theComparableinterface to compare dinosaurs based on their age. - Similarly, our employees also have common behaviors. Define a
Workerinterface with methods that represent these behaviors and implement it in theEmployeeclass...