CSharp-Learning/lessons/Lesson06/Animals/Animal.cs
Rosmontis_Cloud f604d53191 Initial commit: C# 学习笔记和示例代码
- Lesson 01-10: C# 基础语法
- WebView2: 集成示例
- notes/: 详细笔记
2026-07-01 16:31:35 +08:00

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} 发出了声音");
}
}
}