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. day29 进程

    1..操作系统知识 顾名思义,进程即正在执行的一个过程.进程是对正在运行程序的一个抽象. 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一.操作系统的 ...

  2. python3 生成器笔记

    #生成器def MyDemo(M): for i in range(M): yield i**2for item in MyDemo(9): print(item) # #生成器import sysa ...

  3. UML箭头

    继承(泛化):用实线空心三角箭头表示 实现(接口):用虚线空心三角形箭头标示 依赖:虚线箭头,类A指向类B 方法参数需要传入另一个类的对象,就表示依赖这个类 关联:实线箭头,类A指向类B 一个类的全局 ...

  4. 基于wireshark抓包分析TCP的三次握手

    1. TCP的三次握手 在TCP/IP协议通讯过程中,采用三次握手建立连接,从而保证连接的安全可靠. 所有基于TCP的通信都需要以两台主机的握手开始.这个握手过程主要是希望能达到以下不同的目的.[1] ...

  5. 加解密---Java安全

    一.概述 1.JCA(Java Cryptography Architecture) 提供基本的加密框架(消息摘要.数字签名......) 2.JCE(Java Cryptography Extens ...

  6. 本地git的使用

    git和svn的解析 git 教程 git rebase的用法 attion: one:  git中是严格区分大小写的,文件名字大小写敏感 two:  git中分为:工作区,暂存区,分支 three: ...

  7. 虚拟机中Centos7搭建本地仓库

    iso放入光驱(虚拟机光驱)后,设备目录是/dev/sr0 表示光驱,被挂载道 /run/media/c4t/CentOS\ 7\ x86_64目录下 [c4t@localhost ~]$ df文件系 ...

  8. VS Code Plugins And Configuration

    VS Code插件 vscode-icons: 显示文件类型的图标 project manager: 管理项目, 项目的保存加载与切换 beautify: 控制缩进 code runner: 执行代码 ...

  9. Datastructure

    时间复杂度的计算 计算最坏情况下执行语句的次数(含有n) 去掉常数项, 只保留最高项, 去掉系数 最后的结果一般是1, logn, n, nlogn, n^2, 2^n, n!, n^n 时间复杂度所 ...

  10. C#读写txt文件的方法

    1.添加命名空间 System.IO; System.Text; 2.文件的读取 #region 读取TXT文本文件 /// <summary> /// FileStream读取文本文件 ...