添加Lesson12的练习

This commit is contained in:
2025-09-08 16:04:02 +08:00
parent cc5ce287f3
commit 7854f97a29
3 changed files with 51 additions and 0 deletions
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Lesson12_继承_继承的基本概念练习</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,34 @@
namespace Lesson12_继承_继承的基本概念练习
{
class Human
{
public string name;
public int age;
public void Speak()
{
Console.WriteLine("说话");
}
}
class Warrior : Human
{
public int atk;
public void Attack()
{
Console.WriteLine("攻击");
}
}
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
Warrior w = new Warrior();
w.name = "HK";
w.age = 18;
w.Speak();
w.atk = 5;
w.Attack();
}
}
}