public class Bird { | |
public virtual void Fly() { Console.Write("Fly"); } | |
} | |
public class Eagle : Bird { | |
public override void Fly() { Console.Write("Eagle Fly"); } | |
} | |
public class Duck : Bird { | |
public override void Fly() { Console.Write("Duck Fly"); } | |
} | |
public class Penguin : Bird { | |
public override void Fly() { throw new NoFlyException(); } | |
} | |
var birds = new List { new Bird(), new Eagle(), new Duck(), new Penguin() }; | |
foreach(var bird in birds) bird.Fly(); | |
// Tới pengiun thì lỗi vì cánh cụt quăng Exception |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment