Advertisement
desislava_topuzakova

клас Car

Apr 13th, 2024
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using System;
  2. namespace DemoCapsulation
  3. {
  4. public class Car
  5. {
  6. //полета -> характеристики
  7. //access modifiers / модификатори за достъп
  8. //private -> достъпно само в рамките на класа
  9. //public -> достъпно навсякъде
  10. //internal -> default modifier
  11. private string color;
  12. private int year;
  13. private string brand;
  14.  
  15. //get -> осигурява достъп до стойността на полето
  16. //set -> можем да задаваме стойност на полето
  17. public string Color { get; set; }
  18. public int Year { get; set; }
  19. public string Brand { get; set; }
  20.  
  21. //конструктор -> метод, чрез който създаваме обекти от класа
  22. public Car()
  23. {
  24. //default contructor -> съществува винаги, когато се създаде един клас
  25. //създава празен обект
  26. }
  27.  
  28. public Car(string color, int year, string brand)
  29. {
  30. //нов празен обект
  31. this.Color = color;
  32. this.Year = year;
  33. this.Brand = brand;
  34. }
  35.  
  36.  
  37. //методи
  38.  
  39. }
  40. }
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement