從簡單的寥寥語句,完成繼承機制..
/*
* Created by SharpDev.
* User: quone
* Date: 2008-12-27
* Time: 0:03
*
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace jizhi
{
class Program
{
public class Person
{
public virtual void Fun1(int i)
{
Console.WriteLine(i);
Console.WriteLine("吃飯");
}
public void Fun2(Person a)
{
a.Fun1(99);//
Fun1(100);
Console.WriteLine("睡覺");
}
}
public class Man : Person
{
public override void Fun1(int i)
{
base.Fun1(i + 1);
Console.WriteLine("刮胡子");
}
}
//
static void Main(string[] args)
{
//Man man=new Man();
Person person=new Person();
Man man = new Man();
person.Fun2(man);
man.Fun2(person);
}
}
}
結果:
100
吃飯
刮胡子
200
吃飯
睡覺
99
吃飯
201
吃飯
刮胡子
睡覺
//