using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 抽象类
{
class Program
{
//抽象类和抽象方法staticvoid Main(string[] args)
{
Animal a = new Dog();
Animal b = new Cat();
a.Bark();
b.Bark();
Console.ReadKey();
}
}
publicabstractclass Animal
{
publicabstractvoidBark();
//抽象属性(自动属性)publicabstractstring Name
{
get;
set;
}
}
publicclass Dog : Animal
{
publicoverridevoidBark()
{
Console.WriteLine("狗叫");
}
publicoverridestring Name
{
get
{
thrownew NotImplementedException();
}
set
{
thrownew NotImplementedException();
}
}
}
publicclass Cat : Animal
{
publicoverridevoidBark()
{
Console.WriteLine("猫叫");
}
publicoverridestring Name
{
get
{
thrownew NotImplementedException();
}
set
{
thrownew NotImplementedException();
}
}
}
}