using System;
public class Person //基类
{
private string name;
private int age;
private long ID;
public Person(string n, int a, long i)
{
name = n;
age = a;
ID = i;
}
public virtual void Display()
{
Console.WriteLine("Name: " + name);
Console.WriteLine("Age: " + age);
Console.WriteLine("ID: " + ID);
}
}
public class Employee : Person //派生类
{
private string department;
private decimal salary;
//派生类中的构造函数中的基类中的参数要注意!!!!
public Employee(string n, int a,long i, string d, decimal s)
: base(n, a,i)
{
department = d;
salary = s;
}
public override void Display()
{
base.Display();
Console.WriteLine("Department: " + department);
Console.WriteLine("Salary: " + salary);
}
}
class shiy
{
public static void Main()
{
Person p = new Person("张三", 20, 1001);
p.Display();
Console.WriteLine();
Employee a = new Employee("李四",22,1002,"软件教研室",3000.01m);
a.Display();
}
}
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。