// 抽象类必须使用abstract来修饰
public abstract class Person
{
// 抽象方法必须使用abstract来修饰,不能使用virtual或者static修饰
public abstract void sayHello();
}
public class Student : Person
{
public override void sayHello()
{
Console.WriteLine("Student------->sayHello");
}
}
public class Teacher : Person
{
public override void sayHello()
{
Console.WriteLine("Teacher------>sayHello");
}
}
class Start
{
static void Main(string[] args)
{
Person stu = new Student();
Teacher tea = new Teacher();
stu.sayHello();
tea.sayHello();
Console.ReadLine();
}
}
C#_抽象类和抽象方法
最新推荐文章于 2024-01-04 19:14:36 发布