Advertisement
Tishy

C# Virtual and Override

Oct 23rd, 2019
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.44 KB | None | 0 0
  1. /* A method can be declared as virtual, that way it can be changed with override in inheriting classes */
  2.     class Pet
  3.     {        
  4.         public virtual void Eat()
  5.         {
  6.             Console.WriteLine("Your pet thinks about what it may have for dinner today.");
  7.         }
  8.     }
  9.  
  10.     class Cat : Pet
  11.     {
  12.         public override void Eat()
  13.         {
  14.             Console.WriteLine("Your cat eats something.");
  15.         }
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement