Files
2025-09-09 11:34:15 +08:00

33 lines
737 B
C#

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