Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace laba1
- {
- class Program
- {
- static void Main(string[] args)
- {
- // создание объекта класса HardDrive через конструктор по умолчанию
- // и установка полей c помощью set методов
- HardDrive seagate = new HardDrive();
- seagate.Manufacturer = "Seagate";
- seagate.Capacity = 50000;
- seagate.Iface ="SATA II";
- seagate.PrintInfo();
- // создание объекта класса HardDrive с помощью перегруженного конструктора
- HardDrive toshiba = new OutsideHardDrive("Toshiba", 50000, "SATA", "Metal");
- toshiba.PrintInfo();
- Console.ReadLine();
- }
- }
- public class HardDrive
- {
- private string manufacturer;
- protected int capacity; // megabytes
- private string iface;
- public string Description = "HDD";
- public HardDrive()
- {
- }
- public HardDrive(string manufacturer, int capacity, string iface)
- {
- this.manufacturer = manufacturer;
- this.capacity = capacity;
- this.iface = iface;
- }
- public string Manufacturer {
- get
- {
- return manufacturer;
- }
- set
- {
- if (value != null) manufacturer = value;
- }
- }
- public int Capacity {
- get
- {
- return capacity;
- }
- set
- {
- capacity = value;
- }
- }
- public string Iface {
- get {
- return iface;
- }
- set
- {
- if (value != null) iface = value;
- }
- }
- public virtual string showInfo()
- {
- return "Manufactorer: " + manufacturer + ", " +
- "Capacity: " + capacity + ", " +
- "Interface: " + iface + ", " +
- "Type: " + Description;
- }
- // обращени родительского метода к методам наследника
- public void PrintInfo() { Console.WriteLine(showInfo()); }
- }
- public class OutsideHardDrive : HardDrive
- {
- public new int capacity; // переопределение модификатора доступа поля capacity
- private string corpys; // новое поле - Корпус
- public string Corpys
- {
- get
- {
- return corpys;
- }
- set
- {
- if (value != null) corpys = value;
- }
- }
- public OutsideHardDrive(string manufacturer, int capacity, string iface, string corpys)
- : base(manufacturer, capacity, iface) {
- this.corpys = corpys;
- }
- public override string showInfo()
- {
- return "Manufactorer: " + Manufacturer + ", " +
- "Capacity: " + Capacity + ", " +
- "Interface: " + Iface + ", " +
- "Corpys: " + Corpys + ", " +
- "Type: " + Description;
- }
- }
- }
Add Comment
Please, Sign In to add comment