The goal for this exercise is to make sure that you can use polymorphic methods on objects that are stored in an array.
What you need to do to prepare for this exercise:
In the Program.cs file inside provided starter project, in the Polymorphism_And_Arrays.RunExercise()
method, you will note that code is provided to you that creates an array that can hold multiple instances of
the GeneralPrinter
class. You need to do everything that is specified below:
Examine the code in the Polymorphism_And_Arrays.RunExercise()
method. This code should
compile without error, and run without error, before you’ve added any extra classes/methods/etc.
As you do this exercise, if you find errors in the provided code, you should pro-actively fix
those errors.
In particular, your code should not crash.
Add a new class that derives from GeneralPrinter
- name it SpecificPrinter
.
It should override the PrintTheMessage()
method, and print out the message "Message from
a SpecificPrinter
object!". You will need to modify some of the code that has
been provided to you, in order to make this work.
In Polymorphism_And_Arrays.RunExercise()
, create 2 more GeneralPrinter
s, and a total
of 3 SpecificPrinter
objects. You can put them wherever you want in the array. Make
sure that your code successfully calls appropriate the PrintTheMessage()
method on all five objects.