TheBulgarianWolf

OOP Fields And Properties

Jul 3rd, 2021
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. class Human
  2. {
  3.    
  4.     private int height;
  5.     private int weight;
  6.    
  7.     public int Height
  8.     {
  9.         get
  10.         {
  11.             return height;
  12.         }
  13.         set
  14.         {
  15.             height = value;
  16.         }
  17.     }
  18.    
  19.     public int Weight
  20.     {
  21.         get
  22.         {
  23.             return weight;
  24.         }
  25.         set
  26.         {
  27.             weight = value;
  28.         }
  29.     }
  30.    
  31.     public Human(int height,int weight)
  32.     {
  33.         this.height = height;
  34.         this.weight = weight;
  35.     }
  36.    
  37.     public void HumanProps()
  38.     {
  39.         Console.WriteLine("This human is {} cms long and weights {1} kgs.",Height,Weight);
  40.     }
  41. }
  42.  
  43. class EntryPoint
  44. {
  45.     public void Main()
  46.     {
  47.         Human Ivan = new Human(182,85);
  48.         Ivan.Height = 186;
  49.         Ivan.HumanProps();
  50.     }
  51. }
Add Comment
Please, Sign In to add comment