继承使用
//记者:我是记者 我的爱好是偷拍 我的年龄是34 我是一个男狗仔
//司机:我叫舒马赫 我的年龄是43 我是男人 我的驾龄是 23年
//程序员:我叫孙全 我的年龄是23 我是男生 我的工作年限是 3年
Reporter.ref=new Reporter("龙某某",21,'女',拍照);
ref.ReporterHello();
Dirver.dir=ner Dirver("陈某某",21.'男',23);
dir.DirverHello();
Programmer.pro=new Programmer("夏某某",32,'女',3);
pro.ProgrammerHello();
console.ReadKey();
public class person
{
private string _name;
public string Name
{
get{return _name};
set{_name=value};
}
private int _age;
public int Age
{
get{return _age}
set{_name=Name}
}
private char _gender;
public char Gender
{
get{return _gender}
set{_gender=value}
}
public person(string name,int age,char gender)
{
this.Name=name;
this.Age=age;
this.Gender=gender;
}
}
public class Reporter:person
{
private string _hobby;
public string Hoppy
{
get{return _hobby};
set{_hobby=value}
}
public Reporter(string name,int age,char gender,string hobby)
:base(name,age,gender)
{
this.Hoppy=hobby;
}
public void ReporterHello()
{
Console.WriteLine("我是记者,我叫{0},年龄{1},我是{2}生,爱好{3}",this.Name,this.Age,this.Gender,this.Hobby)
}
}
public class Dirver:person
{
private int _dirvertime;
public int DirverTime
{
get{return _dirvertime}
set{_dirvertime=value}
}
public Dirver(string name,int age,char gender,int dirvertime)
:base(name,age,gender)
{
this DirverTime=dievertime;
}
public void DirverHello()
{
Console.WriteLine("我是司机,我叫{0},年龄{1},我是{2}生,驾龄{3}",tis.Name,this.Age,this.Gender,this.DirverTime)
}
}
public class Programmer;proson
{
private int _workyear;
public int WorkYear
{
get{return _workyear}
str{_workyear=value}
}
public Programmer(string name,int age,char gender,int workyear)
:base(name,age,gender)
{
this.WorkYear=workyear;
}
public void programmerHello()
{
Console.WriteLine("我是程序员,我叫{0},年龄{1},我是{2}人,我的工作年限{3}",this.Name,this.Age.this.Gender,this.WorkTime);
}
}