1)定义 Person 类,包含姓名和年龄,并正确封装; 2)正确定义 Person...
发布网友
发布时间:2024-09-27 17:34
我来回答
共1个回答
热心网友
时间:2024-09-27 18:08
除了第8点看不懂外
其他答案如下
public class Person
{
public string Name;
public int Age;
/// <summary>
/// 构造函数
/// </summary>
public Person(string name,int age)
{
Name = name;
Age = age;
}
public virtual void showInfo()
{
Console.WriteLine("姓名:"+Name);
Console.WriteLine("年龄:" + Age.ToString());
Console.ReadLine();
}
}
public class Student : Person
{
public string School;
public string Num;
public Student(string name, int age,string school,string num) : base(name, age)
{
Name = name;
Age = age;
School = school;
Num = num;
}
public void Hello()
{
Console.WriteLine("Hello"+ School + Name);
Console.WriteLine();
}
public override void showInfo()
{
Console.WriteLine("学校:" + School);
Console.WriteLine("学号:" + Num);
Console.WriteLine("姓名:" + Name);
Console.WriteLine("年龄:" + Age.ToString());
Console.ReadLine();
}
}
static void Main()
{
Person p1 = new Person("楼主", 20);
p1.showInfo();
Student s1 = new Student("如花", 30, "断罪小学", "170505");
s1.showInfo();
}