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. newCachedThreadPool无上限线程池使用

    1. newCachedThreadPool无上限线程池,   动态根据代码添加线程,   如果线程空闲60秒没有被使用,会自动关闭 package ThreadTest; import java.u ...

  2. management & Actuator

    self define indicator https://docs.spring.io/spring-boot/docs/current/reference/html/production-read ...

  3. JS 打乱数组顺序

    function rand(arr) { var len = arr.length //首先从最大的数开始遍历,之后递减 for(var i = arr.length - 1; i >= 0; ...

  4. 学习ssm

    1.安装配置maven (1)在http://maven.apache.org/download.cgi下载apach-maven-3.5.4-bin.zip (2)将apach-maven-3.5. ...

  5. 在Oracle创建一个自己用的用户及角色

    1.创建一个用户名为LIXIAOLONG,密码为123456的用户. CREATE USER LIXIAOLKONG IDENTIFIED BY 123456; 2.为用户授予连接,资源,管理员角色. ...

  6. java——编译和运行

    Java源代码---->编译器---->Java字节码(即虚拟指令..class文件.特殊的二进制文件.二进制字节码文件)---->jvm---->解释器(jvm的一部分)-- ...

  7. my.资料

    领回梦丹 http://ka.gamedog.cn/card/2036517.html 1. 普陀的加点没有优点缺点之分,只有是否和你的装备般配.这里可以给一些小数据参考. 60级物理防御达到900, ...

  8. ES6使用常量做为函数名

    重点是 要给常量加一个中括号 就是这么任性~ [SET_INFO](state) { state.userInfo = { name: cookie.getCookie('name'), token: ...

  9. UnityError SocketException: 以一种访问权限不允许的方式做了一个访问套接字的尝试。

    SocketException: 以一种访问权限不允许的方式做了一个访问套接字的尝试. 以管理员身份运行Unity就可以了,权限不够的问题.

  10. Murano Weekly Meeting 2016.05.10

    Meeting time: 2016.May.10 1:00~2:00 Chairperson:  Serg Melikyan, from Mirantis Meeting summary: 1. m ...