添加Lesson14和Lesson15
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user