public class L1
{
//字段!
public string name;
public int age;
//构造函数
public L1()
{
Console.WriteLine("类1的构造函数!");
}
public L1(string name, int age)
{
Console.WriteLine("☆★●→" + name + "■■&▲" + age);
}
//方法
public string F1()
{
return "欢迎:" + name + "!!!";
}
}
public class l2 : L1
{
public string a;
public int b;
public l2()
{
Console.WriteLine("类2输出:");
}
public l2(string a, int b) : base(a, b)
{
//调用了父类里面的构造函数所以我们不用再次在这里赋值!
//Console.WriteLine("☆★●→" + a + "■■&▲" + b);
}
public void F2()
{
Console.WriteLine("传说中的:"+a);
}
}
public class L
{
static void Main()
{
L1 l = new L1( "小默",20);
l.name = "小默";
//l.age = 20;
l.F1();
Console.WriteLine(l.F1 ());
l2 l0 = new l2("坏蛋",20);
//l0.a = ;
//l0.b = 20;
l0.a = "盗贼";
l0.F2();
}
}
输出结果:
☆★●→小默■■&▲20
欢迎:小默!!!
☆★●→坏蛋■■&▲20
传说中的盗贼