Why does testMammal.BreastFeed() called by testMammal not call the BreastFeed method of Mammals class? What is the type of testMammal? Does the left side indicate type or the right side? Mammals testMammal = (aWhale as Mammals)
using System;
using System.Collections.Generic;
namespace ConsoleApplication3
{
class Mammals
{
public string age { get; set; }
public virtual void BreastFeed()
{
Console.WriteLine("This animal Breastfeeds its young ones.");
}
}
class Fish : Mammals
{
public int FinsNum { get; set; }
public override void BreastFeed()
{
Console.WriteLine("This animal Breastfeeds its young ones fish style");
}
}
class Program
{
static void Main(string[] args)
{
Fish aWhale = new Fish();
//Mammals testMammal = (Mammals)aWhale;
Mammals testMammal = (aWhale as Mammals);
testMammal.BreastFeed();
}
}
}