• 接口与类继承学习笔记[0]


    一:接口

      显式实现接口;

      为了实现接口,类可以定义显式接口成员执行体(Explicit interface member implementations)。显式接口成员执行体可以是一个方法、一个属性、一个事件或者是一个索引指示器的定义,定义与该成员对应的全权名应保持一致。

    using System ;
    interface ICloneable {
     object Clone( ) ;
    }
    interface IComparable {
     int CompareTo(object other) ;
    }
    class ListEntry: ICloneable, IComparable {
     object ICloneable.Clone( ) {…}
     int IComparable.CompareTo(object other) {…}
    }


      上面的代码中ICloneable.Clone 和IComparable.CompareTo 就是显式接口成员执行体。从形势上看,也就是使用了完整的名称空间路径(这个说法好象有问题)。

        当在实现多个接口的时候,如果出现多个接口的内有成员完全相同(包括名称,返回值,参数),在实现类里只出现一个实现的方法或属性(默认),这样多个接口使用同一实现,如果想在类里面出现多个实现,应该对每个要实现的成员使用显示方法实现接口!

    二:类继承中的方法

       如果基类:

      public  string  s1(string s)
      {
       return "class2";
      }

    public virtual string  s1(string s)
      {
       return "class2";
      }

    派生类:public new  string  s1(string s)
      {
       return "class3";
      }

    public override string  s1(string s)
      {
       return "class2";
      }

    那么在new class3()后使用s1()返回结果"class3";(我原来以为是使用了new后会有些不同,看来原来的想法是错误的~)


     

  • 相关阅读:
    Spring Cloud 学习推荐
    Spring-Boot-应用可视化监控
    How to Convert a Class File to a Java File?
    Nacos Cluster Building
    基于Opentracing+Jaeger全链路灰度调用链
    Opentracing + Uber Jaeger 全链路灰度调用链,Nepxion Discovery
    What happened when new an object in JVM ?
    Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials
    APK重签名总结
    C++矩阵运算库推荐
  • 原文地址:https://www.cnblogs.com/pojia/p/287745.html
Copyright © 2020-2023  润新知