C#学习小记4 下面的例子是关于方法复载
//下面的例子是关于方法复载.
using System;
public class Student
{ private string name;
public string Name
{
get {return name;}
set { name =value;}
}
public virtual void Print()
{
Console.WriteLine(Name);
}
}
public class GraduateStudent:Student
{
private string undergraduateDegree;
public string UndergraduateDegree
{
get {return undergraduateDegree;}
set { undergraduateDegree =value;}
}
public override void Print()
{ Console.WriteLine(Name+UndergraduateDegree);
}
}
public class Do
{static void Main()
{GraduateStudent o=new GraduateStudent();
o.Name="我是";
o.UndergraduateDegree="研究生";
o.Print();
}
}
//实验成功!!
//下面的例子是关于方法复载.?但是我用到了base.Print();
using System;
public class Student
{ private string name;
public string Name
{
get {return name;}
set { name =value;}
}
public virtual void Print()
{
Console.WriteLine(Name);
}
}
public class GraduateStudent:Student
{
private string undergraduateDegree;
public string UndergraduateDegree
{
get {return undergraduateDegree;}
set { undergraduateDegree =value;}
}
public override void Print()
{base.Print(); //此处我用到了base.Print();
Console.WriteLine(UndergraduateDegree);
}
}
public class Do
{static void Main()
{GraduateStudent o=new GraduateStudent();
o.Name="我是";
o.UndergraduateDegree="研究生";
o.Print();
}
}
//实验成功!!