运行结果

代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 派生
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Undergraguate u = new Undergraguate();
string name = textBox2.Text;
int age = int.Parse(textBox3.Text);
string subject = textBox4.Text;
textBox1.Text = u.GetMessage(name, age, subject);
textBox1.Text += "\r\n" + u.Study();
}
}
public class Student
{
protected string name;
protected int age;
public string Study()
{
string result;
result = string.Format("Student({0}):我是基类的方法。我今年{1}岁,我没毕业,正在学习。\r\n", name, age);
return result;
}
public Student()
{
this.age = 8;
}
}
public class Undergraguate : Student
{
public string subject;
public Undergraguate() : base()
{
subject = "软工";
age++;
}
public string GetMessage(string name, int age, string subject)
{
this.name = name;
this.age = age;
this.subject = subject;
string result;
result = string.Format("Undergraguate({0}):我是派生类的方法。我今年{1}岁,我毕业了,专业是:{2}\r\n", name, age, subject);
return result;
}
}
}