摘要: 一、虚方法实现多态1,创建一个people基类using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 继承之抽象类{ public class people { public virtual void SayHi()//定义一个SayHi的虚方法 { } }}2.创建两个子类Student.cs和Teacher.cs继承基类peopleusing System;using System.Collections.Generi... 阅读全文
posted @ 2014-01-26 12:40 LiuHuaTao 阅读(364) 评论(0) 推荐(0) 编辑
摘要: 一、如何用接口实现多态?1.定义一个接口。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 继承之抽象类{ public interface people //定义一个接口People { void SayHi(); //定义一个SayHi方法 }}2.创建两个类Student.c和Teacher.cs继承接口using System;using System.Collections.Generic;using... 阅读全文
posted @ 2014-01-26 12:24 LiuHuaTao 阅读(379) 评论(0) 推荐(0) 编辑
摘要: 一、什么叫做多态?统一操作作用于不同类的实例,不同类将进行不同的解释,最后产生不同的执行结果。简单来说就是统一指令,对于不同的个体会产生不同的行为。二、如何通过抽象方法实现多态?1.创建一个基类people.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 继承之抽象类{ abstract class people //抽象类 { public abstract void SayHi();//抽象方法 }}2.创建... 阅读全文
posted @ 2014-01-26 11:25 LiuHuaTao 阅读(1285) 评论(0) 推荐(0) 编辑