Kolecioner

C# Транспорт конструктор испольуя getset

Oct 4th, 2023
160
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | Source Code | 0 0
  1. using System;
  2.  
  3. public class Transport
  4. {
  5.     protected string brand;
  6.     protected string model;
  7.     protected int year;
  8.     protected string color;
  9.  
  10.     public Transport(string brand, string model, int year, string color)
  11.     {
  12.         this.brand = brand;
  13.         this.model = model;
  14.         this.year = year;
  15.         this.color = color;
  16.     }
  17.  
  18.     public string Brand
  19.     {
  20.         get { return brand; }
  21.         set { brand = value; }
  22.     }
  23.  
  24.     public string Model
  25.     {
  26.         get { return model; }
  27.         set { model = value; }
  28.     }
  29.  
  30.     public int Year
  31.     {
  32.         get { return year; }
  33.         set { year = value; }
  34.     }
  35.  
  36.     public string Color
  37.     {
  38.         get { return color; }
  39.         set { color = value; }
  40.     }
  41. }
  42.  
  43. public class Car : Transport
  44. {
  45.     public Car(string brand, string model, int year, string color)
  46.         : base(brand, model, year, color)
  47.     {
  48.     }
  49.  
  50.     public void Drive()
  51.     {
  52.         Console.WriteLine("Driving the car");
  53.     }
  54. }
  55.  
  56. public class Bike : Transport
  57. {
  58.     public Bike(string brand, string model, int year, string color)
  59.         : base(brand, model, year, color)
  60.     {
  61.     }
  62.  
  63.     public void Ride()
  64.     {
  65.         Console.WriteLine("Riding the bike");
  66.     }
  67. }
Comments
Add Comment
Please, Sign In to add comment