父类:Employee
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _2018_4_26_jicheng
{
class Employee
{
public string Name{get;set;}
public int Age { get; set; }
public Employee(string name,int age)
{
this.Name = name;
this.Age = age;
}
public Employee()
{
}
}
}
子类1:SE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _2018_4_26_jicheng
{
//项目经理
class SE:Employee
{
public int gongzuoexperience;
public SE(String name,int age,int experience):base(name,age)
{
this.gongzuoexperience = experience;
}
public string sayhi()
{
string message = string.Format("大家好,我是{0},我的名字叫{1},我的工作经验{2}年了", Name, Age, gongzuoexperience);
return message;
}
}
}
子类2:PM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _2018_4_26_jicheng
{
//程序员
class PM:Employee
{
public int personzhi;
public PM(String name,int age,int person):base(name,age)
{
this.personzhi = person;
}
public string sayhi()
{
string message = string.Format("大家好,我是{0},我的名字叫{1},我的人气值高达{2}", Name, Age, personzhi);
return message;
}
}
}
主方法:Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _2018_4_26_jicheng
{
class Program
{
static void Main(string[] args)
{
PM pm = new PM("张三",20,100);
SE se = new SE("李四", 19, 6);
Console.WriteLine(pm.sayhi());
Console.WriteLine(se.sayhi());
}
}
}
运行结果: