Advertisement
Yo_Mb

Yo_21Mb

Oct 13th, 2019
115
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. }
  36. namespace Cow
  37. {
  38. public class Cow : Animal.Animal
  39. {
  40.  
  41. public Cow(String Name, int Weigth, String Sound)
  42. {
  43. this.Name = Name;
  44. this.Weigth = Weigth;
  45. this.Sound = Sound;
  46. }
  47. public Cow(String Name, int Weigth)
  48. {
  49. this.Name = Name;
  50. this.Weigth = Weigth;
  51. this.Sound = "mooo";
  52. }
  53. public Cow(String Name)
  54. {
  55. this.Name = Name;
  56. this.Weigth = 0;
  57. this.Sound = "mooo";
  58. }
  59. public Cow()
  60. {
  61. this.Name = "Unnamed";
  62. this.Weigth = 0;
  63. this.Sound = "mooo";
  64. }
  65.  
  66. }
  67. }
  68. namespace Snake
  69. {
  70. public class Snake : Animal.Animal
  71. {
  72. public Snake(string name, int weigth, string sound) : base(name, weigth, sound)
  73. {
  74. sound = "shhh";
  75. }
  76. }
  77. public class Pig : Animal.Animal
  78. {
  79. public Pig(string name, int weigth, string sound) : base(name, weigth, sound)
  80. {
  81. sound = "oink";
  82. }
  83. }
  84.  
  85. static void Main(string[] args)
  86. {
  87. Cow.Cow animal1 = new Cow.Cow("Bessy", 0, "MOOOOOO");
  88. Console.WriteLine(animal1.Name + " " + animal1.Weigth + " " + animal1.Sound);
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement