Color Point Extensions ***
On this page we have seen the class ColorPoint, which inherits from Point. The classes make use of virtual methods.
In this exercise you should start with the code in this file.
- First take a look at the existing stuff, and make sure you understand it. Be aware that
both of the classes Point and ColorPoint use virtual methods.
- Add a method class-of to both Point and ColorPoint that returns the class of an instance.
- Now repair the method add in Point, such that it always instantiate a class corresponding to the class of the receiver.
In other words, if the receiver of add is a Point, instantiate a Point. If the receiver of add is a ColorPoint, instantiate a ColorPoint. You can probably use the method class-of from above. You may encounter a problem, because the constructor of point and color-point take a different number of parameters.
You are welcome to default the color of a color point to your favorite color!