//接口的包容.
using System;
public interface ITeacher
{
bool AgreeToTeach();     
void Print(string b);   
}                        
public class Professor:ITeacher     
{
private int course;
public int Course
{
   set{course=value;}
   get{return course;}
}
public bool AgreeToTeach()  
{
   if(Course==1)
     return true;
   else
     return false;
}
public void Print(string a)
{
   Console.WriteLine(this.AgreeToTeach()+a);
}
}
public class Student:ITeacher     
{
private int course;
public int Course
{
   set{course=value;}
   get{return course;}
}
public bool AgreeToTeach()  
{
   if(Course==1)
     return true;
   else
     return false;
}
public void Print(string a)
{
   Console.WriteLine(this.AgreeToTeach()+a);
}
}
public class Do
{
private ITeacher teach;
public ITeacher Teach
{
   get{return teach;}
   set{teach=value;}
}
static void Main()
{
   Do c=new Do();
   Professor p=new Professor();
   c.Teach=p;
   c.Teach.Print("professor");
   Student m=new Student();
   c.Teach=m;
   c.Teach.Print("student");
}
}


相关文章:

  • 2022-12-23
  • 2021-10-16
  • 2021-11-03
  • 2022-01-05
  • 2021-05-16
  • 2021-06-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-18
  • 2021-11-18
  • 2022-12-23
  • 2021-05-03
  • 2021-10-27
  • 2022-02-07
  • 2021-12-18
相关资源
相似解决方案