lesson12练习更改

This commit is contained in:
2025-09-09 11:11:14 +08:00
parent 40dca79e2b
commit 307b255d02
2 changed files with 6 additions and 8 deletions
@@ -90,7 +90,7 @@
ChineseTeacher ct = new ChineseTeacher(); ChineseTeacher ct = new ChineseTeacher();
ct.name = "唐老师"; ct.name = "HK";
ct.number = 2; ct.number = 2;
ct.subject = "语文"; ct.subject = "语文";
ct.SpeakName(); ct.SpeakName();
@@ -11,10 +11,9 @@
} }
class Warrior : Human class Warrior : Human
{ {
public int atk; public void Attack(Warrior OtherWarrior)
public void Attack()
{ {
Console.WriteLine("攻击"); Console.WriteLine("{0}攻击{1}",name,OtherWarrior.name);
} }
} }
internal class Program internal class Program
@@ -24,11 +23,10 @@
Console.WriteLine("Hello, World!"); Console.WriteLine("Hello, World!");
Warrior w = new Warrior(); Warrior w = new Warrior();
w.name = "HK"; w.name = "HK";
w.age = 18;
w.Speak(); w.Speak();
w.atk = 5; Warrior w2 = new Warrior();
w.Attack(); w2.name = "KH";
w2.Attack(w);
} }
} }
} }