class Teacher : Person {
private string title; private string department;
public Teacher(int tid, string tname, string ttitle, string tdep) : base(tid, tname) {
title = ttitle; department = tdep; }
public override void infoPrint() {
Console.WriteLine(\ Teacher's Id: {0}\, id); Console.WriteLine(\ Teacher's Name: {0}\, name); Console.WriteLine(\ Teacher's Title: {0}\, title);
Console.WriteLine(\ Teacher's Department: {0}\, department); } }
class Student : Person {
private int classNum ; private int score;
public Student(int tid, string tname, int cNum, int sco) : base(tid, tname) {
classNum = cNum; score = sco; }
public override void infoPrint() {
Console.WriteLine(\ Student's ID: {0}\, id); Console.WriteLine(\ Student's Name: {0}\, name);
Console.WriteLine(\ Student's Class number: {0}\, classNum); Console.WriteLine(\ Student's Score: {0}\, score); } } }
//Program.cs
using System;
using System.Collections.Generic; using System.Linq; using System.Text;
namespace TeacherAndStudent
{
class Program {
static void Main(string[] args) {
Console.WriteLine(\);
Teacher t = new Teacher(86, \, \, \); t.infoPrint();
Console.WriteLine(\);
Student s = new Student(101, \, 2, 90); s.infoPrint(); } } }
情况二: //Person.cs
using System;
using System.Collections.Generic; using System.Linq; using System.Text;
namespace TeacherAndStudent {
class Person {
private int id; private string name;
public Person(int pid, string pname) {
id = pid; name = pname; }
public virtual void infoPrint() {
Console.WriteLine(\, id); Console.WriteLine(\, name); } }
class Teacher : Person {
private string title; private string department;
public Teacher(int tid, string tname, string ttitle, string tdep)
: base(tid, tname) {
title = ttitle; department = tdep; }
public override void infoPrint() {
base.infoPrint();
Console.WriteLine(\, title);
Console.WriteLine(\, department); } }
class Student : Person {
private int classNum ; private int score;
public Student(int tid, string tname, int cNum, int sco) : base(tid, tname) {
classNum = cNum; score = sco; }
public override void infoPrint() {
base.infoPrint();
Console.WriteLine(\, classNum); Console.WriteLine(\, score); } } }
//Program.cs
using System;
using System.Collections.Generic; using System.Linq; using System.Text;
namespace TeacherAndStudent {
class Program {
static void Main(string[] args) {
Console.WriteLine(\);
Teacher t = new Teacher(86, \, \, \);
t.infoPrint();
Console.WriteLine(\);
Student s = new Student(101, \, 2, 90); s.infoPrint(); } } }