fork download
  1. using System;
  2.  
  3. class Weapon
  4. {
  5. // Not static anymore!
  6. public int WeaponDamage { get; set; }
  7. }
  8.  
  9. class Sword : Weapon
  10. {
  11. // Added ctor
  12. public Sword()
  13. {
  14. WeaponDamage = 12;
  15. }
  16. }
  17.  
  18. class Dagger : Weapon
  19. {
  20. public Dagger()
  21. {
  22. WeaponDamage = 4;
  23. }
  24. }
  25.  
  26. public class Test
  27. {
  28. public static void Main()
  29. {
  30. Weapon sword = new Sword();
  31. Weapon dagger = new Dagger();
  32.  
  33. Console.WriteLine("Sword's damage is {0}", sword.WeaponDamage); // 12
  34. Console.WriteLine("Dagger's damage is {0}", dagger.WeaponDamage); // 4
  35.  
  36. // TODO
  37. // player = new Player;
  38. // player.Hand = sword;
  39. // player.Inventory.put(dagger);
  40. }
  41. }
  42.  
Success #stdin #stdout 0s 131520KB
stdin
Standard input is empty
stdout
Sword's damage is 12
Dagger's damage is 4