Inheritance
To prove that mapLocation
class is a subclass from Point
class, we could change the Point
class to mapLocation
class in Game
class.
class Game
{
static void Main(string[] args)
{
Map map = new Map(8, 5);
Point p = new Point(4, 2);
bool isOnMap = map.onMap(p);
Console.WriteLine(isOnMap);
MapLocation mapLoc = new MapLocation(8, 5);
isOnMap = map.onMap(mapLoc);
Console.WriteLine(isOnMap);
Console.WriteLine(mapLoc.distanceTo(5, 2));
Console.Read();
}
}
And we could add this code to strengthen our assumption.
Console.WriteLine(mapLoc is MapLocation);
Console.WriteLine(mapLoc is Point);
Console.WriteLine(p is MapLocation);