W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
using System; namespace MyApplication { // 抽象类 abstract class Animal { // 抽象方法(没有方法体) public abstract void animalSound(); // 普通方法 public void sleep() { Console.WriteLine("Zzz"); } } // 派生类(继承自 Animal) class Pig : Animal { public override void animalSound() { // animalSound() 方法的方法体在这里提供 Console.WriteLine("The pig says: wee wee"); } } class Program { static void Main(string[] args) { Pig myPig = new Pig(); // 创建一个 Pig 对象 myPig.animalSound(); // 调用 animalSound() 方法 myPig.sleep(); // 调用 sleep() 方法 } } }