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. cf Permute Digits(dfs)

    C. Permute Digits You are given two positive integer numbers a and b. Permute (change order) of the ...

  2. kafka的offset和ProcessingGuarantee

    https://blog.csdn.net/xianpanjia4616/article/details/84347087 https://m.2cto.com/net/201703/616024.h ...

  3. linux安装php7

    之前一直对linux研究的比较少,终于下定决心好好把linux玩一下 首先~我是安装了vm虚拟机,然后使用的是centos7的版本.因为vm不好复制粘贴,故使用了xshell连接了我的linux进行操 ...

  4. Forbidden You don't have permission to access XXX on this server

    Forbidden You don't have permission to access / on this server. 找到 apache 配置文件 httpd.conf 把里面的 <D ...

  5. Angular JS ng-repeat 报错 Error: [ngRepeat:dupes]

    ng-repeat常用情况: <div class="form-group" ng-repeat="item in items"></div& ...

  6. jeecg权限设置案例

    JEECG简单实例讲解权限控制 一.业务背景 某公司要实现一个日志系统,用来了解员工的工作量饱和情况. 二.需求 1.角色分为:员工.经理两种. 2.员工每天在日志系统中填报工作总结,然后经理进行点评 ...

  7. DRF-->2序列化组件的使用和接口设计--get,post,put,delete&优化组件

    !!!!! !!!!! 记住这个图 !!!!! 上篇博客说道DRF序列化组件的get,只是简单的举一个实例,然而在现实生活中我们前后端进行交互的时候更多的用到了Json数据格式,这也就是说前后端交互的 ...

  8. Linux常用操作命令介绍

     Linux常用操作命令介绍 重要概念 CPU:就像人的大脑,主要负责相关事情的判断以及实际处理的机制.查询指令:cat /proc/cpuinfo 内存:大脑中的记忆区块,将皮肤.眼睛等所收集到的信 ...

  9. JS arguments转array

    JS arguments转array? Array.prototype.slice.call(arguments)

  10. DEDE把变量放进session中,结果取值为null的问题

    最近在基于织梦CMS(dedecms)做公司网站,可以说改动不少,而其中最令我印象深刻的就是织梦的session.    自己想在前台页面限制一些用户的访问,且后台用户可以访问.必须验证织梦后台用户的 ...