using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 继承
{
class Program
{
static void Main(string[] args)
{
Student s = new Student();
s.name = "guo";
s.SayHello();
Teacher t1 = new Teacher("翟老师",18,'女',100,90,80);
t1.SayHi();
t1.ShowScore();
Teacher t2 = new Teacher("翟老师",20,'女');
t2.SayHi();
Console.ReadKey();
}
}
class person
{
public void SayHello()
{
Console.WriteLine("我是人类");
}
}
class Student : person
{
public string name { get; set; }
public new void SayHello()
{
string name = "wang";
Console.WriteLine("我是学生,我的名字是"+name);//使用局部变量的name
Console.WriteLine("我是学生,this的名字是" + this.name);
}
}
class Teacher
{
public string Name { get; set; }
public int Age { get; set; }
public char Gender { get; set; }
public int Chinese { get; set; }
public int Math { get; set; }
public int English { get; set; }
//Teacher 构造函数
public Teacher(string name, int age, char gender, int chinese, int math, int english)
{
this.Name = name;
this.Age = age;
this.Gender = gender;
this.Chinese = chinese;
this.Math = math;
this.English = english;
}
public Teacher(string name, int age, char gender)//
: this(name, age, gender, 0, 0, 0)
{ }
public void SayHi()
{
Console.WriteLine("我叫{0},今年{1}岁了,我是{2}生",this.Name,this.Age,this.Gender);
}
public void ShowScore()
{
Console.WriteLine("我叫{0},我的总成绩是{1},平均成绩是{2}", this.Name, this.Chinese + this.Math + this.English, (this.Chinese + this.Math + this.English)/3.0);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 继承
{
class Program
{
static void Main(string[] args)
{
Student s = new Student();
s.name = "guo";
s.SayHello();
Teacher t1 = new Teacher("翟老师",18,'女',100,90,80);
t1.SayHi();
t1.ShowScore();
Teacher t2 = new Teacher("翟老师",20,'女');
t2.SayHi();
Console.ReadKey();
}
}
class person
{
public void SayHello()
{
Console.WriteLine("我是人类");
}
}
class Student : person
{
public string name { get; set; }
public new void SayHello()
{
string name = "wang";
Console.WriteLine("我是学生,我的名字是"+name);//使用局部变量的name
Console.WriteLine("我是学生,this的名字是" + this.name);
}
}
class Teacher
{
public string Name { get; set; }
public int Age { get; set; }
public char Gender { get; set; }
public int Chinese { get; set; }
public int Math { get; set; }
public int English { get; set; }
//Teacher 构造函数
public Teacher(string name, int age, char gender, int chinese, int math, int english)
{
this.Name = name;
this.Age = age;
this.Gender = gender;
this.Chinese = chinese;
this.Math = math;
this.English = english;
}
public Teacher(string name, int age, char gender)//
: this(name, age, gender, 0, 0, 0)
{ }
public void SayHi()
{
Console.WriteLine("我叫{0},今年{1}岁了,我是{2}生",this.Name,this.Age,this.Gender);
}
public void ShowScore()
{
Console.WriteLine("我叫{0},我的总成绩是{1},平均成绩是{2}", this.Name, this.Chinese + this.Math + this.English, (this.Chinese + this.Math + this.English)/3.0);
}
}
}