1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleAbstact
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Train t = new Train();
- Car c = new Car();
- Vehicle v = t;
- v.Name = "火车";
- v.Move();
- Console.ReadLine();
- }
- }
- abstract class Vehicle
- {
- public string Name { get; set; }
- public abstract void Move();
- }
- class Train : Vehicle
- {
- public override void Move()
- {
- Console.WriteLine("{0}在铁轨上行驶", Name);
- }
- }
- class Car : Vehicle
- {
- public override void Move()
- {
- Console.WriteLine("{0}在公路上行驶",Name);
- }
- }
- }
|