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. java Sprint boot 学习之一

    <properties> <project.build.sourceEncoding>UTF-</project.build.sourceEncoding> < ...

  2. B. Sereja and Suffixes

    B. Sereja and Suffixes time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. layui的表单功能

    作为一个phper还是非常喜欢这个插件的~虽然在vue的群里面说这个插件好被人怼过..废话不多说, 这次使用到的是layui的表单功能.上次的日历忘记做笔记了非常可惜,大部分其实跟着文档撸就可以,这次 ...

  4. 简述wcf应用

    一.新建wcf 如下图:wcf可以简历俩种形式 1.库文件,就是一个类库文件,可以用windows服务或控制台开启. 2.服务应用程序,可以直接IIS上面发布. 二.库文件自动生成的类 接口类 usi ...

  5. hutool http+天气预报

    中国天气接口:http://www.weather.com.cn/data/sk/地址.html,只显示当天. sojson接口:http://t.weather.sojson.com/api/wea ...

  6. robot framework 的AutoItLibrary常用关键字

    1.run 的用法,以及激活当前窗口

  7. Linux cp命令拷贝 不覆盖原有的文件

    cp 参数说明: -i或--interactive  覆盖既有文件之前先询问用户. -r  递归处理,将指定目录下的文件与子目录一并处理. -R或--recursive  递归处理,将指定目录下的所有 ...

  8. stm32串口学习(二)

    今天继续学习stm32的串口编程(利用库函数).上次我们说了串口的发送,这次我们说接收. 接收可以用查询的方法,也可以用中断.显然,工程中多用中断的方式,那么就来看看中断接收. 代码其实很简单,基本的 ...

  9. DEDE图集手工上传图片,加入水印

    DEDE的图集手工上传图片,是一个非常好用的flash上传图片工具.但是如果我们希望上传的图片,带有自己网站指定的水印,却发现没有达到我们的要求--那么如果我们确实希望上传的图片,带有水印,怎么办?以 ...

  10. 查看服务器配置信息prtdiag与systeminfo实用命令

    UNIX(SUN服务器)bash-2.05# prtdiag -v系统配置:  Sun Microsystems  sun4u Sun Fire V890系统时钟频率:150 MHz内存大小:3276 ...