Skip to content

Instantly share code, notes, and snippets.

@tuannguyenssu
Created July 7, 2019 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuannguyenssu/d76e2e9165002ca798fe2c292293174a to your computer and use it in GitHub Desktop.
Save tuannguyenssu/d76e2e9165002ca798fe2c292293174a to your computer and use it in GitHub Desktop.
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