C#学习小记12实现一个接口

//实现一个接口
using System;
public interface ITeacher
{
bool AgreeToTeach();      //注意!无需用public abstract
void Print(string b);     //注意!无需用public abstract
}                         //声明一个接口
public class Professor:ITeacher       //实现接口
{
private int course;
public int Course
{
   set{course=value;}
   get{return course;}
}
public bool AgreeToTeach()   //无需用override
{
   if(Course==1)
     return true;
   else
     return false;
}
public void Print(string a)
{
   Console.WriteLine(this.AgreeToTeach()+a);
}
static void Main()
{
   Professor a=new Professor();
   a.Course=1;
   a.Print("! this is yatasoft");
}
}

posted on 2008-08-06 13:28  yatasoft  阅读(174)  评论(0编辑  收藏  举报

导航