| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
 
namespace 基类的引用实例 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 
            MyDerivedClass derived = new MyDerivedClass();  //派生类的实例化. 
            MyBaseClass mybc= derived;  //转换成基类 
           //MyBaseClass mybcc = new MyBaseClass(); 
            derived.Print();   //从派生类部分调用Print. 
            mybc.Print();      //从基类部分调用Print. 
            //mybcc.Print(); 
            Console.ReadKey(); 
        } 
    } 
    class MyBaseClass 
    { 
        public void Print() 
        { 
            Console.WriteLine("This is the base class."); 
        } 
    } 
    class MyDerivedClass : MyBaseClass 
    { 
        new public void Print() 
        { 
            Console.WriteLine("This is the derived class."); 
        } 
    } 
} 
 
输出结果: 
 
This is the derived class. 
This is the base class. |   
 
 
 
 |