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

28 lines
581 B
C#

using System;
namespace Lesson06.Animals
{
class Dog : Animal
{
private string breed;
// base(name) 调用父类的构造函数
public Dog(string name, string breed) : base(name)
{
this.breed = breed;
}
public void Info()
{
Console.WriteLine($"名字: {name}, 品种: {breed}");
}
// 重写父类方法
public override void Speak()
{
base.Speak(); // 先调用父类方法
Console.WriteLine($"{name} 汪汪汪!");
}
}
}