logo
  • 教程列表
  • SO官方文档
  • 继承
    • 继承。构造函数调用序列
    • 继承自基类
    • 继承自类并实现接口
    • 从类继承并实现多个接口
    • 测试和导航继承
    • 扩展抽象基类
    • 子类中的构造函数
    • 继承反模式
    • 继承方法
    • 具有递归类型规范的基类
  1. StackOverflow 文档
  2. C# Language 教程
  3. 继承
  4. 继承自类并实现接口

继承自类并实现接口

Created: November-22, 2018

public class Animal 
{
    public string Name { get; set; }
}

public interface INoiseMaker
{
    string MakeNoise();
}

//Note that in C#, the base class name must come before the interface names
public class Cat : Animal, INoiseMaker
{
    public Cat() 
    {
        Name = "Cat";
    }

    public string MakeNoise()
    {
        return "Nyan";
    }
}
  • 从类继承并实现多个接口
  • 继承自基类

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明