zoukankan      html  css  js  c++  java
  • 20.明白接口实现和虚函数实现的区别

    接口实现没有多态功能, 以接口调用接口方法,其性质表现为实现接口的类的方法行为。

    若要让接口实现多态功能,需要用virtual 实现。如下:

    public interface IA
        {
            void Print();
        }

        public class MyClass:IA
        {
            public virtual void Print()
            {
                Console.WriteLine("MyClass");
            }
        }
        public class MyDerive : MyClass
        {
            public override void Print()
            {
                Console.WriteLine("MyDerive");
            }
        }

        static void Main(string[] args)
            {
                //Program.print();

                MyDerive myderve = new MyDerive();
                myderve.Print();
                IA ia = myderve as IA;
                ia.Print();
                MyClass myclass = myderve as MyClass;
                myclass.Print();
            }

  • 相关阅读:
    0326系统按钮添加权限的工作(jsp权限写法)
    0321菜单数据
    ztree树的递归
    前端padding margin
    解决1像素边框问题
    水平垂直居中
    移动端css公共样式
    tap方法改良this指向
    移动端常见问题
    前端笔记(兼容)
  • 原文地址:https://www.cnblogs.com/movemoon/p/2738353.html
Copyright © 2011-2022 走看看