Onece a class implementation a particular interface, you can interact with the members of the interface through any instance of that class.

 Cow bossie = new Cow("Bossie", );

 // Cow implements IMoo, which includes Moo method
bossie.Moo();

You can also declare a variable whose type is an interface, assign it to an instance of any class that implements that interface and then interact with members of the interface through that interface variable.

 // bossie is a Cow, which implements IMoo, so we can point IMoo variable at her
IMoo mooer = bossie;
mooer.Moo();

Notice that we can't access members of Cow that aren't part of IMoo using this interface variable.

 // Can't call Cow methods not in IMoo
mooer.MakeSomeMilk();

Even though MakeSomeMilk is a public method in the Cow class, we can't access it via IMoo.

原文地址:#437 – Access Interface Members through an Interface Variable

【转载】#437 - Access Interface Members through an Interface Variable的更多相关文章

  1. 【Go入门教程6】interface(interface类型、interface值、空interface{}、嵌入interface、反射)

    interface Go语言里面设计最精妙的应该算interface,它让面向对象,内容组织实现非常的方便,当你看完这一章,你就会被interface的巧妙设计所折服. 什么是interface 简单 ...

  2. 【Go入门教程8】interface(interface类型、interface值、空interface{}、嵌入interface、反射)

    interface Go语言里面设计最精妙的应该算interface,它让面向对象,内容组织实现非常的方便,当你看完这一章,你就会被interface的巧妙设计所折服. 什么是interface 简单 ...

  3. Move resources allocated using unmanaged interface to managed devm interface

    转载:http://blog.csdn.net/swingboard/article/details/27207497   So today let’s talk about devm functio ...

  4. JAVA的abstract修饰符 && 接口interface用法 && 抽象类和interface的差别

    abstract修饰符可以修饰类和方法. (1)abstract修饰类,会使这个类成为一个抽象类,这个类将不能生成对象实例,但可以做为对象变量声明的类型(见后面实例),也就是编译时类型.抽象类就相当于 ...

  5. 一个Interface 继承多个Interface 的总结

    我们知道在Java中的继承都是单继承的,就是说一个父类可以被多个子类继承但是一个子类只能有一个父类.但是一个接口可以被不同实现类去实现,这就是我们说的Java中的多态的概念.下面我们再来说一下接口的多 ...

  6. Single document interface和Multiple document interface

    https://en.wikipedia.org/wiki/Single_document_interface https://msdn.microsoft.com/en-us/library/b2k ...

  7. 关于C#你应该知道的2000件事

    原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...

  8. 【转载】#440 - A Class Can Implement More than One Interface

    It's possible for a class to implement more than one interface. For example, a Cow class might imple ...

  9. IPoint Interface接口

    Description A Point is a zero-dimensional object that represents a specific (X, Y) location in a the ...

随机推荐

  1. 关于form组件的补充-------formChoice

    form组件的Choice字段 还是基于出版社和书的模型来详解 models.py(模型) from django.db import models # Create your models here ...

  2. MySQL SQL_MODE详解

    http://blog.itpub.net/29773961/viewspace-1813501/

  3. python3 读取表格的数据

    python3 读取表格的数据 xlrd1.1.0的下载网址:https://pypi.python.org/pypi/xlrd. xlrd1.1.0兼容python2和python3. python ...

  4. python模块之numpy

    Numpy是一个第三方库,是数组相关的运算 通过pip安装:pip install numpy Anaconda python的一个科学计算发行版本,安装后将不必单独安装numpy,下面的库模块也将不 ...

  5. 技巧:Python中print打印信息的同时打印文件、行号

    import sys def Log(msg): print('Print Message: '+msg+' ,File: "'+__file__+'", Line '+str(s ...

  6. ssh两台主机建立信任关系

    A主机(10.104.11.107)   B主机(10.104.11.128) A: ssh-keygen -t rsa [root@H0f .ssh]# ssh-keygen -t rsa Gene ...

  7. 性能测试工具Jmeter07-Jmeter性能测试实战

    测试需求:测试20个用户访问www.baozhenart.com在负载达到30QPS时的平均响应时间 QPS:Query Per Second每秒查询率.是一台查询服务器每秒能够处理的查询次数.在因特 ...

  8. caffe学习资料

    1.利用Caffe做回归(regression) http://www.cnblogs.com/frombeijingwithlove/p/5314042.html

  9. jquery dataTable 自定义 Button及按钮事件

    参考网址:http://stackoverflow.com/questions/18134913/jquery-datatabletabletool-custom-buttons-calling-ev ...

  10. 监听outlook新邮件

    using System; using System.Linq; using Microsoft.Office.Interop.Outlook; using System.Collections.Ge ...