【转载】#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 ...
 
随机推荐
- ORA-14517: Subpartition of index "string.string" is in unusable state
			
今天碰到个ORA-03113, 原因不明. 猜测因为某些table DDL操作过后导致index unuable的case, 然后进行analyze table, 再碰到ORA-14517. 最后通 ...
 - 阿里Java开发规约插件使用
			
刚刚的云栖大会上,阿里巴巴公布了这款酝酿已久的Java开发规约插件,对于国内开发者来说是一次轻松提高自己代码规范的机会. 安装方法 IDEA安装方法: settings >> plugin ...
 - Electron、Node.js、JavaScript、JQuery、Vue.js、Angular.js,layui,bootstrap
			
转载:https://blog.csdn.net/meplusplus/article/details/79033786 layui :是基于jquery库的封装开发. bootstrap:同样基于 ...
 - 3	不用IDE开发groovy
			
1 不用IDE开发groovy 1.1 不用IDE开发的方法 可以在IDE中运行Groovy类或者脚本,但是Groovy也提供了其他运行途径.你能运行Groovy代码基于以下: · ...
 - sf03_杨辉三角go实现
			
package main import "fmt" /* 变量规范 全局变量以v_为前缀 函数形参以p_为前缀 函数内部变量,字母数字下划线等普通组合,其中函数返回值以out_为前 ...
 - Mybatis学习笔记2 - 解析config
			
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC ...
 - android Activity启动过程(四)startActivityUncheckedLocked
			
final int startActivityUncheckedLocked(ActivityRecord r, ActivityRecord sourceRecord, IVoiceInteract ...
 - JobService 7.0 定时任务不生效
			
代码 // 构建JobInfo对象,传递给JobSchedulerService JobInfo.Builder builder = new JobInfo.Builder(JOB_ID,new Co ...
 - Java基础02-变量
			
1.为什么要使用变量? 变量就是用来记忆数据的,它是一个记忆系统 2.什么是变量? 变量就是一个容器,用来装数据的,变量是放在内存里的. 比如:内存是酒店,变量名就是房间名,变量值就是住进房间的人 3 ...
 - 微信web开发者工具 && 微信调试页面
			
微信开发者工具 做微信公众号的过程中,自然避免不了登录账号然后进行调试,但是在chrome上我们没有办法登录,这是一个令人头疼的问题,比如这个公众号网页,只会提示出错,因为开发者限制了公众号网页的登录 ...