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

最新文章

  1. sigaction和sigqueue
  2. [译]How to Install Node.js on Ubuntu 14.04 如何在ubuntu14.04上安装node.js
  3. 还在花钱搞开发?猿团YTFCloud,零基础照样做专业APP
  4. C++ STL 学习 :for_each与仿函数(functor)
  5. protobuf-net
  6. java 指导 (Java Tutorial)
  7. 辛星Spring4.x教程开放下载了
  8. Facebook 添加点赞按钮
  9. zk分布式任务管理
  10. JAVA实现等腰三角形
  11. IntelliJ IDEA 创建Spring+SpringMVC+hibernate+maven项目
  12. html 存放PDF文档
  13. 在angularjs实现一个时钟
  14. Code::Blocks代码自动提示设置及常用快捷键
  15. Java:大文件拆分工具
  16. 【前端安全】JavaScript防XSS攻击
  17. 阿里云流计算BLINK
  18. UVA 11806 Cheerleaders (容斥原理
  19. [转]EntityFramework Core技术线路(EF7已经更名为EF Core,并于2016年6月底发布)
  20. 修改ubuntu密码

热门文章

  1. Go语言基础之14--Waitgroup和原子操作
  2. VMware硬盘空间——扩容
  3. Python中的sin和cos函数
  4. TypeScript -- JavaScript的救赎
  5. Mybatis学习笔记6 - #{}和${}
  6. caffe学习资料
  7. BaseAdapter,SimpleAdapter,CursorAdapter的用法
  8. DevStack添加Swift
  9. axios处理http请求
  10. Kudu1.1.0 、 Kudu1.2.0 Kudu1.3.0的版本信息异同比较