请按照题目的要求编写程序并给出运行结果。
1.设计一个学生类Student和它的一个子类Undergraduate,并进行测试,提示如下。
(1)Student 类有 Name(姓名)和Age(年龄)属性,一个包含两个参数的构造方法,用于给
Name和Age属性赋值,一个Show()方法打印 Student的属性信息。
(2)本科生类 Undergraduate 增加一个Degree(学位)属性。有一个包含3个参数的构造方法,
前两个参数用于给继承的Name和Age属性赋值,第三个参数用于给 Degree 属性赋值,一个
ShowO方法用于打印 Undergraduate的属性信息。
(3)在测试类中分别创建 Student 对象和 Undergraduate 对象,调用它们的 Show()方法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Student
    {
        public string Name{get;set;}
        public int Age { get; set; }

        public Student(string _Name, int _Age)
        {
            Name = _Name;
            Age = _Age;
        }

        public virtual void Show()
        {
            Console.WriteLine("Name= " + Name);
            Console.WriteLine("Age= " + Age);
        }
    }

    class Undergraduate : Student
    {
        public string Degree { get; set; }

        public Undergraduate(string _Name, int _Age, string _Degree):base(_Name, _Age)
        {
            Degree = _Degree;
        }

        public override void Show()
        {
            base.Show();
            Console.WriteLine("Degree= " + Degree);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Student s = new Student("林忆宁",114);
            Undergraduate u = new Undergraduate("七海Nana7mi", 514,"带硕");
            s.Show();
            u.Show();
            Console.ReadKey();
        }
    }