26 lines
447 B
C#
26 lines
447 B
C#
using System;
|
|
|
|
namespace Lesson06.Animals
|
|
{
|
|
class Animal
|
|
{
|
|
protected string name;
|
|
|
|
public Animal(string name)
|
|
{
|
|
this.name = name;
|
|
}
|
|
|
|
public void Eat()
|
|
{
|
|
Console.WriteLine($"{name} 在吃东西");
|
|
}
|
|
|
|
// virtual 允许子类重写
|
|
public virtual void Speak()
|
|
{
|
|
Console.WriteLine($"{name} 发出了声音");
|
|
}
|
|
}
|
|
}
|