zoukankan      html  css  js  c++  java
  • 接口详解

    using System;

    namespace cSharpJichu
    {  
        interface IInterface
        {
            void InterfaceClassA();
            void InterfaceClassB();
        }

        public class ImplementInterfaceClass : IInterface
        {
            private string a = "在 ImplementInterfaceClass 类内部的变量";
            public void InterfaceClassA()
            {
                Console.WriteLine("RunAtImplementInterfaceClass InterfaceClassA");
            }

            public void InterfaceClassB()
            {
                Console.WriteLine("RunAtImplementInterfaceClass InterfaceClassB");
            }

            public void InterfaceClassC()
            {
                Console.WriteLine(this.a);
            }
        }

        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine();
                Console.WriteLine("------------------ 以下是实现接口测试 ------------------------");
                ImplementInterfaceClass iic = new ImplementInterfaceClass();
                iic.InterfaceClassA();
                iic.InterfaceClassB();
                iic.InterfaceClassC();
                Console.WriteLine("------------------ 以上是实现接口测试 ------------------------");

                Console.Read();
            }
        }
    }

    运行结果:

     

    总结:

    1.接口中方法没有实现体,只有声明.

    2.接口中的方法不能加修改符[public internal protected private ], 默认为public

    3.类在实现接口时,必须实现接口中所有声明的方法

  • 相关阅读:
    VScode快捷键:单行注释和多行注释
    常见状态码的含义
    2019年10月22日 文件操作复习
    2019年10月7日 函数复习
    2019年10月4日 元类
    2019年10月2日 property补充
    2019年10月1日 实现延迟计算功能
    2019年9月30日 property流程分析
    2019年9月29日 自定制property
    2019年9月23日 类的装饰器的应用
  • 原文地址:https://www.cnblogs.com/bicabo/p/1646571.html
Copyright © 2011-2022 走看看