Program.cs 856 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ConsoleAbstact
  7. {
  8. internal class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. Train t = new Train();
  13. Car c = new Car();
  14. Vehicle v = t;
  15. v.Name = "火车";
  16. v.Move();
  17. Console.ReadLine();
  18. }
  19. }
  20. abstract class Vehicle
  21. {
  22. public string Name { get; set; }
  23. public abstract void Move();
  24. }
  25. class Train : Vehicle
  26. {
  27. public override void Move()
  28. {
  29. Console.WriteLine("{0}在铁轨上行驶", Name);
  30. }
  31. }
  32. class Car : Vehicle
  33. {
  34. public override void Move()
  35. {
  36. Console.WriteLine("{0}在公路上行驶",Name);
  37. }
  38. }
  39. }