Skip to content

Instantly share code, notes, and snippets.

@conanak99
Created April 25, 2016 22:46
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 conanak99/24dbd016a8258af5dc49f3fc051b93f5 to your computer and use it in GitHub Desktop.
Save conanak99/24dbd016a8258af5dc49f3fc051b93f5 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