定义接口IPerson,有name属性返回值类型为String,和GetScore方法,该方法无参数,有double返回值。
再定义一个接口IStudent,有school属性,和GetScore方法,该方法无参数,有double返回值,还有一个方法add方法,有两个int 参数,返回这两个数之和。
再定义一个类StuEmployee类,继承了IPerson和IStudent.GetScore方法是单独实现的。
在主程序入口,定义类的对象,赋值给IPerson的引用,该引用调用name属性和GetScore方法。
然后再定义类的对象赋值给IStudent引用,该引用调用schooll属性、GetScore方法和add方法。以下是我自己做的,请高手们修正下:class Program
{
static void Main(string[] args)
{
IPerson pe = new StuEmployee();
pe.GetScore(12, 12);
pe.name();
IStudent stu = new StuEmployee();
stu.school();
stu.GetScore();
stu.add(13, 13); }
}
interface IPerson
{
string name
{
get;
set;
}
double GetScore();
}
interface IStudent
{
string school
{
get;
set;
}
double GetScore();
int add(int a, int b);
}
class StuEmployee : IPerson, IStudent
{
double IPerson.GetScore(int a, int b)
{
return a + b;
}
public string name
{
get
{
return "你好";
}
set
{
name = value;
}
}
public string school
{
get
{
return "第一学校";
}
set
{
school = value;
}
}
public int add(int a, int b)
{
Console.WriteLine(a + b);
}
}
再定义一个接口IStudent,有school属性,和GetScore方法,该方法无参数,有double返回值,还有一个方法add方法,有两个int 参数,返回这两个数之和。
再定义一个类StuEmployee类,继承了IPerson和IStudent.GetScore方法是单独实现的。
在主程序入口,定义类的对象,赋值给IPerson的引用,该引用调用name属性和GetScore方法。
然后再定义类的对象赋值给IStudent引用,该引用调用schooll属性、GetScore方法和add方法。以下是我自己做的,请高手们修正下:class Program
{
static void Main(string[] args)
{
IPerson pe = new StuEmployee();
pe.GetScore(12, 12);
pe.name();
IStudent stu = new StuEmployee();
stu.school();
stu.GetScore();
stu.add(13, 13); }
}
interface IPerson
{
string name
{
get;
set;
}
double GetScore();
}
interface IStudent
{
string school
{
get;
set;
}
double GetScore();
int add(int a, int b);
}
class StuEmployee : IPerson, IStudent
{
double IPerson.GetScore(int a, int b)
{
return a + b;
}
public string name
{
get
{
return "你好";
}
set
{
name = value;
}
}
public string school
{
get
{
return "第一学校";
}
set
{
school = value;
}
}
public int add(int a, int b)
{
Console.WriteLine(a + b);
}
}
{
return a + b;
}
static void Main(string[] args)
{
IPerson p = new StuEmployee();
p.name = "John";
Console.WriteLine(p.name + "," + p.GetScore());
IStudent s = new StuEmployee();
s.school = "PKU";
Console.WriteLine(s.school + "," + s.GetScore() + "," + s.add(1, 2));
#endregion } interface IPerson
{
string name
{
get;
set;
}
double GetScore();
}
interface IStudent
{
string school
{
get;
set;
}
double GetScore();
int add(int a, int b);
}
class StuEmployee : IPerson, IStudent
{
private string n;
public string name
{
get { return n; }
set { n = value; }
} private string sch;
public string school
{
get { return sch; }
set { sch = value; }
} public double GetScore()
{
return 0;
} double IStudent.GetScore()
{
return 1;
} public int add(int a, int b)
{
return a + b;
}
}
{
string name
{
set;
get;
}
double GetScore(); }
interface IStudent
{
string school
{
set;
get;
}
double GetScore();
int add(int a, int b);
}
class StuEmploy : IPerson, IStudent
{
private string School;
private string Name;
double IPerson.GetScore()
{
return 0;
}
double IStudent.GetScore()
{
return 0;
}
public int add(int a, int b)
{
return a + b;
}
public string school
{
set
{
School = value;
}
get
{
return School;
}
}
public string name
{
set
{
Name = value;
}
get
{
return Name;
}
}
}
class Program
{
static void Main(string[] args)
{
IPerson p = new StuEmploy();
IStudent s = new StuEmploy();
p.name = "NAME";
Console.WriteLine(p.name);
p.GetScore();
s.school = "SCHOOL";
Console.WriteLine(s.school);
s.GetScore();
Console .WriteLine ( s.add(2, 3)); }
}