关于C#中Student类和Teacher类对Person类的继承有关问题,求教代码哪出错了
关于C#中Student类和Teacher类对Person类的继承问题,求教代码哪出错了
------解决方案--------------------
public class Teacher : Person被定义在public class Student : Person的{}里面了,把他移到外面去
------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Person
{
protected int id;
protected string name;
public Person(int pid, string pname)
{
id = pid;
name = pname;
}
public virtual void infoPrint()
{
Console.WriteLine("Person's Id: {0}", id);
Console.WriteLine("Person's Name: {0}", name);
}
}
public class Student : Person
{
protected int class_id;
protected int score;
public Student(int pid, string pname,int sclass_id,int sscore)
{
id = pid;
name = pname;
class_id = sclass_id ;
score = sscore;
}
public new void infoPrint()
{
Console.WriteLine("Person's Id: {0}", id);
Console.WriteLine("Person's Name: {0}", name);
Console.WriteLine("Person's Class_id: {0}", class_id);
Console.WriteLine("Person's Score: {0}", score);
}
public class Teacher : Person
{
protected String position;
protected string department;
public Teacher(int pid, string pname, String tposition,String tdepartment)
{
id = pid;
name = pname;
position = tposition;
department = tdepartment;
}
public override void infoPrint()
{
Console.WriteLine("Person's Id: {0}", id);
Console.WriteLine("Person's Name: {0}", name);
Console.WriteLine("Person's Position: {0}", position);
Console.WriteLine("Person's Department: {0}", department);
}
}
}static void Main(string[] args)
{
Person person=newPerson();
Teacher teacher=new Teacher(86,"王宁",jiaoshou,jisuanji);
Student student=new Student(101,"李刚",2,90);
}
}
------解决方案--------------------
public class Teacher : Person被定义在public class Student : Person的{}里面了,把他移到外面去
------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
public class Person
{
protected int id;
protected string name;
public Person(int pid, string pname)
{
id = pid;
name = pname;
}
public virtual void infoPrint()
{
Console.WriteLine("Person's Id: {0}", id);
Console.WriteLine("Person's Name: {0}", name);
}
}
public class Student : Person