【转载】#437 - Access Interface Members through an Interface Variable
2024-08-27 14:20:19
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
最新文章
- sigaction和sigqueue
- [译]How to Install Node.js on Ubuntu 14.04 如何在ubuntu14.04上安装node.js
- 还在花钱搞开发?猿团YTFCloud,零基础照样做专业APP
- C++ STL 学习 :for_each与仿函数(functor)
- protobuf-net
- java 指导 (Java Tutorial)
- 辛星Spring4.x教程开放下载了
- Facebook 添加点赞按钮
- zk分布式任务管理
- JAVA实现等腰三角形
- IntelliJ IDEA 创建Spring+SpringMVC+hibernate+maven项目
- html 存放PDF文档
- 在angularjs实现一个时钟
- Code::Blocks代码自动提示设置及常用快捷键
- Java:大文件拆分工具
- 【前端安全】JavaScript防XSS攻击
- 阿里云流计算BLINK
- UVA 11806 Cheerleaders (容斥原理
- [转]EntityFramework Core技术线路(EF7已经更名为EF Core,并于2016年6月底发布)
- 修改ubuntu密码
热门文章
- Go语言基础之14--Waitgroup和原子操作
- VMware硬盘空间——扩容
- Python中的sin和cos函数
- TypeScript -- JavaScript的救赎
- Mybatis学习笔记6 - #{}和${}
- caffe学习资料
- BaseAdapter,SimpleAdapter,CursorAdapter的用法
- DevStack添加Swift
- axios处理http请求
- Kudu1.1.0 、 Kudu1.2.0 Kudu1.3.0的版本信息异同比较