Advertisement
Yo_Mb

Yo_21Mb

Oct 13th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Animal
  4. {
  5. public abstract class Animal
  6. {
  7. //Attributes
  8. private String name;
  9. private int weigth;
  10. private String sound;
  11. public String Name { get { return name; } set { name = value; } }
  12. public int Weigth { get { return weigth; } set { weigth = value; } }
  13. public String Sound { get { return sound; } set { sound = value; } }
  14.  
  15. //Constructors
  16. public Animal()
  17. {
  18. this.Name = "Unnamed";
  19. this.Weigth = 0;
  20. this.Sound = "Unknown";
  21. }
  22. public Animal(String name, int weigth, String sound)
  23. {
  24. this.Name = name;
  25. this.Weigth = weigth;
  26. this.Sound = sound;
  27. }
  28.  
  29. //Methodes
  30. String says()
  31. {
  32. return Sound;
  33. }
  34. }
  35. public class Cow : Animal
  36. {
  37.  
  38. public Cow(String Name, int Weigth, String Sound)
  39. {
  40. this.Name = Name;
  41. this.Weigth = Weigth;
  42. this.Sound = Sound;
  43. }
  44. public Cow(String Name, int Weigth)
  45. {
  46. this.Name = Name;
  47. this.Weigth = Weigth;
  48. this.Sound = "mooo";
  49. }
  50. public Cow(String Name)
  51. {
  52. this.Name = Name;
  53. this.Weigth = 0;
  54. this.Sound = "mooo";
  55. }
  56. public Cow()
  57. {
  58. this.Name = "Unnamed";
  59. this.Weigth = 0;
  60. this.Sound = "mooo";
  61. }
  62. String says()
  63. {
  64. return Sound = "Mooo";
  65. }
  66.  
  67. }
  68. public class Snake : Animal
  69. {
  70. public Snake(string name, int weigth, string sound) : base(name, weigth, sound)
  71. {
  72. sound = "shhh";
  73. }
  74. }
  75. public class Pig : Animal
  76. {
  77. public Pig(string name, int weigth, string sound) : base(name, weigth, sound)
  78. {
  79. sound = "oink";
  80. }
  81. }
  82.  
  83. static void Main(string[] args)
  84. {
  85. Cow animal1 = new Cow("Bessy", 0, "MOOOOOO");
  86. Console.WriteLine(animal1.Name + " " + animal1.Weigth + " " + animal1.Sound);
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement