I'm studying on abstract methods and abstract classes. I don't understand how the following code runs without a compiler error and prints stackoverflow
. I expected that error because I don't understand how it knows to call Playput
's chew()
method. Could you explain?
using System;
public class Program
{
public static void Main()
{
new Platypus();
}
}
abstract class Mammal
{
abstract public String chew();
public Mammal()
{
Console.WriteLine(chew()); // Does this line compile?
}
}
class Platypus : Mammal
{
override public String chew()
{
return "stackoverflow";
}
}