Creating the Main() program
The next stage here is to create our main program to use these classes. At the bottom of your code, create a new line and type the following:
class Program { }
This will be our main program code and its entry points. Within this, write the following:
static void Main() { }
This is our basic Main
function setup. Now we are going to make a Movable
object. Type the following within curly braces:
Movable movableObject = new Fish();
On the left-hand side of the statement, we have Movable
as the data type, and we're calling it movableObject
. On the right-hand side, because we already have our two classes implementing Movable
, I can put either a new Human
object or a new Fish
object. I'm going to use Fish
for now.
We are going to use this with a switch
block in a way that has not been possible until now. On the next line, type the following:
switch(movableObject) { }
Unlike before, we can switch an entire object. Now we can decide what we're going to do with it,...