Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. public class Program
  2. {
  3. public static void Main()
  4. {
  5. IPerson john = new Man("John", 36, true);
  6. Console.WriteLine(john.GetInfo());
  7. }
  8.  
  9. public interface IPerson
  10. {
  11. string Name { get; set; }
  12. int Age { get; set; }
  13. string Gender { get; set; }
  14. }
  15.  
  16. public abstract class Person : IPerson
  17. {
  18. public Person(string name, int age, string gender)
  19. {
  20. this.Name = name;
  21. this.Age = age;
  22. this.Gender = gender;
  23. }
  24.  
  25. public string Name { get; set; }
  26. public int Age { get; set; }
  27. public string Gender { get; set; }
  28.  
  29. public virtual string GetInfo()
  30. {
  31. return $"{this.Name}-{this.Age}";
  32. }
  33.  
  34. }
  35.  
  36. public class Man : Person
  37. {
  38. public Man(string name, int age, bool isBald)
  39. : base(name, age, "m")
  40. {
  41. this.IsBald = isBald;
  42. }
  43.  
  44. public bool IsBald { get; set; }
  45.  
  46. public override string GetInfo()
  47. {
  48. return $"{base.GetInfo()}-{this.IsBald}";
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement