CS 245 - Programming Languages
Lab 8
Kotlin classes
In this lab you will be writing classes with inheritance in Kotlin. Then you will wite a main method that illustrates the use of those classes. Finally, also in the main, use those classes to validate that Kotlin uses dynamic dispatch.
In all of the programs below you may NOT use
- any variable declared to be a var (either explicitly or implicitly)
- Any loop construct
Consider the following UML:
Write a set of classes that implement this UML. (The colors of text inthe UML are irrelevant). You may use properties or methods for any of the elements in the UML.
You must use inheritance. Dog and cat both extend animal. WorkingDog must extend Dog. Within the classes new properties or methods are indicated by the presence of types.
More Requirements
- Your classes should all be regular classes rather than data classes
- You must have a mix of properties and methods. For instance, ID and name should almost certainly be properties, whereas sound should probably be a method.
- You must override at least one method (in addition to toString())
- You must have a useful toString method for each class
- You must override the default get accessor at least once
- You must have a main function that creates instances of all of these classes and that illustrate their use.
- Your main function should have a code that shows that Kotlin classes use dynamic dispatch.
What to hand in
Send email to gtowell245@cs.brynmawr.edu with the file containing your classes and main function. In addition, write 1-3 sentences that describe how you showed that kotlin uses dynamic dispatch.