using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 抽象类
{
class Program
{
//抽象类和抽象方法
static void Main(string[] args)
{
Animal a = new Dog();
Animal b = new Cat();
a.Bark();
b.Bark();
Console.ReadKey();
}
}
public abstract class Animal
{
public abstract void Bark();
//抽象属性(自动属性)
public abstract string Name
{
get;
set;
}
}
public class Dog : Animal
{
public override void Bark()
{
Console.WriteLine("狗叫");
}
public override string Name
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
}
public class Cat : Animal
{
public override void Bark()
{
Console.WriteLine("猫叫");
}
public override string Name
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
}
}
C#抽象类
最新推荐文章于 2024-04-12 14:38:03 发布