Inheritance

To prove that mapLocationclass is a subclass from Pointclass, we could change the Point class to mapLocation class in Gameclass.

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);

results matching ""

    No results matching ""