当前位置:网站首页>C - Inheritance - hidden method
C - Inheritance - hidden method
2022-07-06 07:07:00 【Tsim Sha Tsui duankun 415】
We cannot delete any member in the parent class , But you can mask the parent member with the same name as the parent member
Grammatical details :
- Mask data members - Declare members with the same name and type in subclasses
- Mask function members : Declare a new member with the same function signature in a subclass
- Let the compiler know : Add new keyword , Otherwise it will call the police
for example , The following are the fields and methods of the parent class
lass Pet
{
public string Name;
public void PrintName()
{
Console.WriteLine("Pet name is " + Name);
}
}Then when a method with the same name is created in a subclass
class Dog:Pet
{
new public void PrintName()// added new After keyword , When called below, it calls the methods of subclasses
{
Console.WriteLine(" The dog's name is " + Name);
}
}The printed result is not the called parent method , In this way, the hidden method can be achieved
Whether we want to call the subclass or the parent PrintName Depends on what we quote
Dog dog = new DogThe subclass will call the subclass
Pet dog = new DogThis call is the parent class , What you print out is Pet name is 了
class Program
{
static void Main(string[] args)
{
Dog dog = new Dog();// If it doesn't new Words , The print out here is in English
dog.Name = "jack";
dog.PrintName(); The dog's name is jack
Pet name is tom边栏推荐
- 作者已死?AI正用藝術征服人類
- 19. Actual memory management of segment page combination
- supervisor 使用文档
- 接口自动化测试框架:Pytest+Allure+Excel
- 医疗软件检测机构怎么找,一航软件测评是专家
- leetcode1020. 飞地的数量(中等)
- Supporting title of the book from 0 to 1: ctfer's growth road (Zhou Geng)
- 微信脑力比拼答题小程序_支持流量主带最新题库文件
- MVVM of WPF
- Fast target recognition based on pytorch and fast RCNN
猜你喜欢

How are the open source Netease cloud music API projects implemented?

AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm

ROS学习_基础

SSM学习

树莓派串口登录与SSH登录方法

Raspberry pie 3B update VIM

leetcode704. 二分查找(查找某个元素,简单,不同写法)

UWA Pipeline 2.2.1 版本更新说明

After working for 10 years, I changed to a programmer. Now I'm 35 + years old and I'm not anxious

Blue Bridge Cup zero Foundation National Championship - day 20
随机推荐
编译,连接 -- 笔记 -2
呆错图床系统源码图片CDN加速与破解防盗链功能
Leetcode35. search the insertion position (simple, find the insertion position, different writing methods)
leetcode841. Keys and rooms (medium)
Thought map of data warehouse construction
前缀和数组系列
Setting and using richview trvstyle template style
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
树莓派3B更新vim
Introduction to ros2 installation and basic knowledge
After working for 10 years, I changed to a programmer. Now I'm 35 + years old and I'm not anxious
leetcode1020. 飞地的数量(中等)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
leetcode841. 钥匙和房间(中等)
Babbitt | metauniverse daily must read: the group image of Chinese Internet enterprises pouring into metauniverse: "there are only various survival desires, and there is no ambition for forward-lookin
hydra常用命令
Kubernetes cluster builds ZABBIX monitoring platform
Three methods of adding color to latex text
PCL实现选框裁剪点云