【转载】#335 - Accessing a Derived Class Using a Base Class Variable
You can use a variable whose type is a base class to reference instances of a derived class.
However, using the variable whose type is the base class, you can use it to access only members of the base class and not members of the derived class.
In the example below, we have two instances of the Terrier class, which derives from Dog. One instance is referenced by a variable of type Terrier. Using this variable, you have access to all members of the Terrier class. On the other hand, the variable whose type is Dog can only reference members of the Dog class, even though the reference points to an instance of a Terrier.
Terrier bubba = new Terrier("Bubba", , "Happy");
bubba.Growl(); // Can call Terrier.Growl Dog jack = new Terrier("Jack", , "Surly");
jack.Growl(); // ERROR: Can't call Growl method
原文地址:#335 - Accessing a Derived Class Using a Base Class Variable
【转载】#335 - Accessing a Derived Class Using a Base Class Variable的更多相关文章
- (转载)1248 - Every derived table must have its own alias
(转载)http://hi.baidu.com/lylegend13/item/a79f17eb51f5dff7e0a5d43b 1. select count(distinct CName) fro ...
- 如何实现 Copying derived entities using only base class pointer
#include <iostream> struct CloneableBase { ; }; template<class Derived> struct Cloneable ...
- 关于C#你应该知道的2000件事
原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...
- 【转载】#330 - Derived Classes Do Not Inherit Constructors
A derived class inherits all of the members of a base class except for its constructors. You must de ...
- [转载] google mock cookbook
原文: https://code.google.com/p/googlemock/wiki/CookBook Creating Mock Classes Mocking Private or Prot ...
- C++ 强制类型转换(转载)
转载自:http://www.weixueyuan.net/view/6329.html 在C++语言中新增了四个关键字static_cast.const_cast.reinterpret_cast和 ...
- 【转载】C++中的基类与派生类
转自:http://www.cnblogs.com/sujz/articles/2044365.html 派生类的继承方式总结: 继承方式 说明 public 基类的public和protected的 ...
- [C++] OOP - Base and Derived Classes
There is a base class at the root of the hierarchy, from which the other class inherit, directly or ...
- 【转载】#344 - Hidden Base Class Member Is Invoked Based on Declared Type of Object
When you use the new modifier to hide a base class method, it will still be called by objects whose ...
随机推荐
- Nginx静态服务,域名解析
安装这里就不写了在LNMP里有具体的安装 1.1 常用来提供静态Web服务的软件有如下三种: Apache:这是中小型Web服务的主流,Web服务器中的老大哥. Nginx:大型网 ...
- Rabbitmq相关学习网址
1.安装文档: http://www.cnblogs.com/shuzhenyu/p/9823324.html 2.RabbitMq的整理 exchange.route.queue关系 https:/ ...
- tomcat的安装部署
第一步: 先把压缩包拖到知道的目录,解压 tar xf apache-tomcat-8.0.27.tar.gz -C /usr/local/ ln -s /usr/local/apache-tomca ...
- webAPI过滤器添加参数签名
项目需求: 接口对安卓和IOS开发接口,需要房子用户窜改数据请求接口.添加sign签名校验参数. 代码如下:加上特性标签就可以控制部分接口验证 public class SignAuthorizeFi ...
- 如何 将下载离线 nupkg 文件 安装到VS2017
https://www.cnblogs.com/cncc/articles/8276878.html --------------------------------------------- ...
- java——注解处理器
Java提供了两种方式来处理注解:第一种是利用运行时反射机制:另一种是使用Java提供的API来处理编译期的注解. 运行时通过反射:仅当定义的注解的@Retention为RUNTIME时,才能够通过运 ...
- tomcat正常关闭,端口号占用解决 StandardServer.await: create[8005]:
cmd进入依次输入以下三个命令 1:netstat -ano | findstr "8005"2:tasklist | findstr "5632" 3:tas ...
- Python函数调用
1.同级目录下的调用 - src |- mod1.py |- test1.py 若在程序test1.py中导入模块mod1.py,则直接使用 import mod1 或 from mod1 impor ...
- GBDT,FM,FFM推导
GBDT推导: https://xgboost.readthedocs.io/en/latest/tutorials/model.html FM,FFM推导: https://tech.meituan ...
- C语言有GetOpenFile吗?
windows中有个GetOpenFile的函数,就是上面那个啦!!我们怎么来实现呢?要我用C语言写出来我真的跪了..但是我们可以输入文件的[绝对路径],配合fopen函数来实现的.. 注意问题 ①文 ...