fork download
  1. using System.IO;
  2. using System;
  3.  
  4. public class Shape
  5. {
  6. public string GetName(){return "shape";}
  7. }
  8.  
  9. public class Ball : Shape
  10. {
  11. public new string GetName(){return "ball";}
  12. }
  13.  
  14. public class Pet
  15. {
  16. public virtual string GetName(){return "pet";}
  17. }
  18.  
  19. public class Cat : Pet
  20. {
  21. public override string GetName(){return "cat";}
  22. }
  23.  
  24. class Program
  25. {
  26. static void Main(string[] args)
  27. {
  28. Pet myPet = new Cat();
  29. Cat johnsCat = new Cat();
  30. Shape shape = new Ball();
  31.  
  32. Console.WriteLine(string.Format("My {0} is playing with a {1}. John's {2} is sleeping", myPet.GetName(), shape.GetName(), johnsCat.GetName()));
  33. }
  34. }
Success #stdin #stdout 0.04s 22264KB
stdin
Standard input is empty
stdout
My cat is playing with a shape. John's cat is sleeping