Files
Csharp/C#核心/Lesson12_继承-继承的基本概念练习/Program.cs
T

33 lines
737 B
C#
Raw Normal View History

2025-09-08 16:04:02 +08:00
namespace Lesson12_继承_继承的基本概念练习
{
class Human
{
public string name;
public int age;
public void Speak()
{
Console.WriteLine("说话");
}
}
class Warrior : Human
{
2025-09-09 11:11:14 +08:00
public void Attack(Warrior OtherWarrior)
2025-09-08 16:04:02 +08:00
{
2025-09-09 11:11:14 +08:00
Console.WriteLine("{0}攻击{1}",name,OtherWarrior.name);
2025-09-08 16:04:02 +08:00
}
}
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
Warrior w = new Warrior();
w.name = "HK";
w.Speak();
2025-09-09 11:11:14 +08:00
Warrior w2 = new Warrior();
w2.name = "KH";
w2.Attack(w);
2025-09-08 16:04:02 +08:00
}
}
}