Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Inheritance
  8. {
  9.  
  10.     public interface IMovable
  11.     {
  12.         void Move();
  13.     }
  14.  
  15.     public abstract class Vehicle
  16.     {
  17.         public string id;
  18.  
  19.         public void PrintId()
  20.         {
  21.             Console.WriteLine(id);
  22.         }
  23.  
  24.         public abstract void SetId(string newId);
  25.     }
  26.  
  27.     public class Transport : Vehicle
  28.     {
  29.         protected string name;
  30.  
  31.         public virtual string GetName()
  32.         {
  33.             return name + " transport";
  34.         }
  35.  
  36.         public void SetName(string value)
  37.         {
  38.             name = value;
  39.         }
  40.  
  41.         public virtual void Volume()
  42.         {
  43.             Console.WriteLine("y");
  44.         }
  45.  
  46.         #region Overrides of Vehicle
  47.  
  48.         public override void SetId(string newId)
  49.         {
  50.             id = newId;
  51.         }
  52.  
  53.         #endregion
  54.     }
  55.  
  56.     public class Car : Transport, IMovable
  57.     {
  58.  
  59.         public void Move()
  60.         {
  61.             Console.WriteLine("car moving");
  62.         }
  63.  
  64.         public override string GetName()
  65.         {
  66.             return name + " car";
  67.         }
  68.  
  69.         public override void Volume()
  70.         {
  71.             Console.WriteLine("x");
  72.         }
  73.  
  74.     }
  75.  
  76.  
  77.     public class Insect : IMovable
  78.     {
  79.         public void Move()
  80.         {
  81.             Console.WriteLine("insect moving");
  82.         }
  83.     }
  84.  
  85.  
  86.  
  87.  
  88.     class Program
  89.     {
  90.         static void Main(string[] args)
  91.         {
  92.             Transport transport = new Transport();
  93.             transport.SetName("transport1");
  94.             Console.WriteLine(transport.GetName());
  95.             transport.Volume();
  96.  
  97.  
  98.             Car car = new Car();
  99.             car.SetName("car");
  100.             Console.WriteLine(car.GetName());
  101.             car.Move();
  102.             car.Volume();
  103.  
  104.  
  105.             //Vehicle v = new Vehicle();
  106.  
  107.             car.id = "6ffg";
  108.             car.PrintId();
  109.  
  110.  
  111.             Insect insect = new Insect();
  112.  
  113.             moveObject(car);
  114.             moveObject(insect);
  115.  
  116.  
  117.  
  118.             Console.ReadKey();
  119.         }
  120.  
  121.         static void moveObject(IMovable myObject)
  122.         {
  123.             myObject.Move();
  124.         }
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement