C# abstract关键字

using System;public abstract class Vehicle {public abstract void display();}public class Bus : Vehicle {

编程学习网为您整理以下代码实例,主要实现:C# abstract关键字,希望可以帮到各位朋友。

using System;

public abstract class Vehicle {
   public abstract voID display();
}

public class Bus : Vehicle {
   public overrIDe voID display() {
      Console.Writeline("Bus");
   }
}

public class Car : Vehicle {
   public overrIDe voID display() {
      Console.Writeline("Car");
   }
}

public class Motorcycle : Vehicle {
   public overrIDe voID display() {
      Console.Writeline("Motorcycle");
   }
}

public class MyClass {
   public static voID Main() {
      Vehicle v;
      v = new Bus();
      v.display();
      v = new Car();
      v.display();
      v = new Motorcycle();
      v.display();
   }
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐