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. linux 远程装机

    首先,服务器配置dhcp  关闭火墙yum install dhcp -ycd   /etc/dhcpcp   /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example ...

  2. CHUCK手把手带你搞定OPENSTACK

    一.OpenStack初探 1.1 OpenStack简介 OpenStack是一整套开源软件项目的综合,它允许企业或服务提供者建立.运行自己的云计算和存储设施.Rackspace与NASA是最初重要 ...

  3. Python学习笔记_零碎知识

    1. 变量本身类型不固定的语言称之为动态语言,与之对应的是静态语言.静态语言在定义变量时必须指定变量类型,如果赋值的时候类型不匹配,就会报错. 2. Python有两种除法: /除法计算结果是浮点数, ...

  4. 生成jvm快照文件

    原文:https://blog.csdn.net/jijianshuai/article/details/79128033  -Xmx20m -Xms5m -XX:HeapDumpOnOutofMem ...

  5. redis的三种启动方式,个人常用第二种

    redis的启动方式1.直接启动  进入redis根目录,执行命令:  #加上‘&’号使redis以后台程序方式运行 1 ./redis-server & 2.通过指定配置文件启动  ...

  6. ASP.NET中多语言的实现

    一个网站可能具备多个语言,要实现这个功能在ASP.NET中是非常简单的.我们需要为项目添加资源文件文件夹,并且添加针对网站的特定的资源文件等即可.在ASP.NET中资源文件分成两类:全局和页面级(即“ ...

  7. javascript典型实例

    你真的已经搞懂JavaScript了吗? 昨天在著名前端架构师Baranovskiy的博客中看到一个帖子<So, you think you know JavaScript?>   题目一 ...

  8. 同源策略引发对跨域jsonp跨域的理解

    一,同源策略其实网络的安全基石,既:http://www.baidu.com:80协议(http或者HTTPS或者ws或者wss).域名(www.baidu.com).端口(默认80,可以不写 htt ...

  9. 服务器断电后 redis重启后启动不起来

    服务器断电后 redis 重启后启动不起来 原因:db持久化失败 1. 先查询redis的进程 ps -ef|grep redis 2. 查询redis的缓存文件在哪 whereis dump.rdb ...

  10. 大话java基础知识一之为什么java的主函数入口必须是public static void

    为什么java的主函数入口必须是public static void main (String[] args); 很多写javaEE好几年的程序员经常会记得java的主函数就是这么写的,但实际上为什么 ...