吕氏替换原则理解

来源:互联网 发布:淘宝手机设置优惠券 编辑:程序博客网 时间:2024/04/30 03:46
个人理解:就是用子类对象去实列化父类的对象;
1.可以调用父类拥有的方法

2.如果父类的方法是虚方法并且被父类重写,那么就可以用父类的对象间接的引用到父类的的方法;

lass Program    {        class father        {            public void Show()            {                Console.WriteLine("我是父类没有虚方法的");            }            public virtual void vShow()            {                Console.WriteLine("我是父类里面有虚方法的");            }        }        class zhulang:father         {            public void  Show()            {                Console.WriteLine("我是子类直接被继承的");            }        }        class zhutao:father         {               public override void vShow()                    {                        Console.WriteLine("我是子类方法被重写了的");                      base.vShow();                    }         }        static void Main(string[] args)        {            father oper = new zhulang ();            oper .Show ();            oper = new zhutao ();            oper .vShow ();            Console .ReadKey ();        }    }


0 0
原创粉丝点击