When you use the new modifier to hide a base class method, it will still be called by objects whose type is the base class. Objects whose type is the derived class will call the new method in the derived class.

 Dog kirby = new Dog("kirby", );

 // Calls Dog.Bark
kirby.Bark(); Terrier jack = new Terrier("Jack", ); // Calls Terrier.Bark
jack.Bark();

The Terrier.Bark method is invoked because the variable jack is declared to be of type Terrier.

We could also use a variable of type Dog (the base class) to refer to an instance of a Terrier (the derived class). If we then call the Bark method using this base class variable, the Bark method in the base class is called, even though we're invoking the method on an instance of the derived class.

 Dog kirby = new Dog("kirby", );

 // Calls Dog.Bark
kirby.Bark(); Dog jack = new Terrier("Jack", ); // Calls Dog.Bark
jack.Bark();

原文地址:#344 - Hidden Base Class Member Is Invoked Based on Declared Type of Object

【转载】#344 - Hidden Base Class Member Is Invoked Based on Declared Type of Object的更多相关文章

  1. leetcode 编译问题:Line x: member access within null pointer of type 'struct TreeNode'

    参考: LEETCODE 中的member access within null pointer of type 'struct ListNode' 解决 leetcode 编译问题:Line x: ...

  2. 【转载】逃离adapter的地狱-针对多个View type的组合实现方案

    英文原文:JOE'S GREAT ADAPTER HELL ESCAPE 转载地址:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015 ...

  3. 141. 环形链表 LeetCode报错:runtime error: member access within null pointer of type 'struct ListNode'

    /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...

  4. 【转载】#324 - A Generic Class Can Have More than One Type Parameter

    A generic class includes one or more type parameters that will be substituted with actual types when ...

  5. 转载 - Vim 的 Python 编辑器详细配置过程 (Based on Ubuntu 12.04 LTS)

    出处:http://www.cnblogs.com/ifantastic/p/3185665.html Vim 的 Python 编辑器详细配置过程 (Based on Ubuntu 12.04 LT ...

  6. 关于C#你应该知道的2000件事

    原文 关于C#你应该知道的2000件事 下面列出了迄今为止你应该了解的关于C#博客的2000件事的所有帖子. 帖子总数= 1,219 大会 #11 -检查IL使用程序Ildasm.exe d #179 ...

  7. Thinking in Java——笔记(8)

    Polymorphism The polymorphic method call allows one type to express its distinction from another, si ...

  8. C# for Beginner Part 21 to 30

    Part 21 Inheritance in c# Why Inheritance Pillars(支架) of Object Oriented Programming 1,Inheritance(继 ...

  9. Thinking in Java,Fourth Edition(Java 编程思想,第四版)学习笔记(八)之Polymorphism

    Polymorphism is the third essential feature of an object-oriented programming language,after data ab ...

随机推荐

  1. java泛型&bean copy list

    参考:https://www.oracle.com/technetwork/cn/articles/java/juneau-generics-2255374-zhs.html E:元素K:键N:数字T ...

  2. 数据层——ImageData层

    layer { name: "data" type: "ImageData" top: "data" top: "label&qu ...

  3. layim和Gatewayworker组合的实时通讯

    今天是第二次重新开发使用layim和Gatewayworker,但是由于第一次没有写文档,导致这一次就跟第一次一样,一头雾水,重新开始看文档研究,导致遇到一个瓶颈,怎么都过不去.所以,以这篇文章开始, ...

  4. django-filter version 2.0 改动

    今天使用django-filter时候遇到了下面这个问题: django-filter: TypeError at /goods/ init() got an unexpected keyword a ...

  5. XGBoost算法

    一.基础知识 (1)泰勒公式 泰勒公式是一个用函数在某点的信息描述其附近取值的公式.具有局部有效性. 基本形式如下: 由以上的基本形式可知泰勒公式的迭代形式为: 以上这个迭代形式是针对二阶泰勒展开,你 ...

  6. Oracle基础篇--01数据库控制语言DCL

    数据库控制语言,是用户对数据的权限控制语言. 通过GRANT语句进行赋权,通过REVOKE撤回权限.数据库的权限包括2种,一种是数据库系统权限,一种是数据库对象权限.在控制语言里面,存在2个概念, 1 ...

  7. c3p0 数据连接池 流行开源

    注意事项:配置文件规定命名,不能更改   c3p0-config <?xml version="1.0" encoding="UTF-8"?>< ...

  8. java 多线程 yield方法的意义

    Thread.yield( )方法: 使当前线程从执行状态(运行状态)变为可执行态(就绪状态).cpu会从众多的可执行态里选择,也就是说,当前也就是刚刚的那个线程还是有可能会被再次执行到的,并不是说一 ...

  9. 判断表单中是否含有disabled属性

    我想判断input里面是否有disabled.或者选中未选中的selected  checked 属性时,需要用  prop()  方法,返回的结果是 true 或 false . attr()这个方 ...

  10. GCC操作

    GCC编译器常用选项 生成动态链接库: gcc file.c -fPIC -o file.so, PIC表示Position-Independent Code: 独立地址代码 编译: gcc -c f ...