Files
Csharp/C#核心/Lesson14_继承-继承中的构造函数练习/Program.cs
T

64 lines
1.5 KiB
C#
Raw Normal View History

2025-09-10 14:43:03 +08:00
namespace Lesson14_继承_继承中的构造函数练习
{
class Worker
{
public string job;
public string content;
public Worker(string job, string content)
{
this.job = job;
this.content = content;
}
public void Work()
{
Console.WriteLine("{0}做了{1}",job,content);
}
}
class Programer : Worker
{
public Programer() : base("程序员", "编程")
{
Console.WriteLine("调用了Programer无参构造");
}
}
class Plan : Worker
{
public Plan() : base("策划", "设计游戏")
{
Console.WriteLine("调用了Plan无参");
}
}
class Art : Worker
{
public Art() : base("美术", "美术设计")
{
Console.WriteLine("调用了Art的无参构造");
}
public void testArt()
{
Console.WriteLine("调用了testArt测试函数");
}
}
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
Programer programer = new Programer();
programer.Work();
Worker art = new Art();
art.Work();
Console.WriteLine(art is Programer);
Console.WriteLine(art is Art);
Console.WriteLine(art is Worker);
Art test = art as Art;
test.testArt();
}
}
}