Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Inheritance
- {
- public interface IMovable
- {
- void Move();
- }
- public abstract class Vehicle
- {
- public string id;
- public void PrintId()
- {
- Console.WriteLine(id);
- }
- public abstract void SetId(string newId);
- }
- public class Transport : Vehicle
- {
- protected string name;
- public virtual string GetName()
- {
- return name + " transport";
- }
- public void SetName(string value)
- {
- name = value;
- }
- public virtual void Volume()
- {
- Console.WriteLine("y");
- }
- #region Overrides of Vehicle
- public override void SetId(string newId)
- {
- id = newId;
- }
- #endregion
- }
- public class Car : Transport, IMovable
- {
- public void Move()
- {
- Console.WriteLine("car moving");
- }
- public override string GetName()
- {
- return name + " car";
- }
- public override void Volume()
- {
- Console.WriteLine("x");
- }
- }
- public class Insect : IMovable
- {
- public void Move()
- {
- Console.WriteLine("insect moving");
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Transport transport = new Transport();
- transport.SetName("transport1");
- Console.WriteLine(transport.GetName());
- transport.Volume();
- Car car = new Car();
- car.SetName("car");
- Console.WriteLine(car.GetName());
- car.Move();
- car.Volume();
- //Vehicle v = new Vehicle();
- car.id = "6ffg";
- car.PrintId();
- Insect insect = new Insect();
- moveObject(car);
- moveObject(insect);
- Console.ReadKey();
- }
- static void moveObject(IMovable myObject)
- {
- myObject.Move();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement