关于继承的一个小程序

using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
    
class Program
    
{
        
static void Main(string[] args)
        
{
            B b 
= new B();
            b.print();
            C c 
= new C();
            c.print();
            Console.ReadKey();
        }

    }

    
class A
    
{
        
public int a = 3;
    }

    
class B : A
    
{
        
public new int a = 4;
        
public virtual void print()
        
{
            Console.WriteLine(
base.a);
        }

    }

    
class C : B
    
{
        
public override  void print()
        
{
            Console.WriteLine(
base.a);
        }

    }

}
会输出
3
4

而如果把class C中的print函数整个删除,会输出
3
3
posted @ 2007-08-28 00:43  张旋  阅读(196)  评论(0编辑  收藏  举报