当前位置:网站首页>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 Dog
The subclass will call the subclass
Pet dog = new Dog
This 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正用藝術征服人類
- ROS learning_ Basics
- PCL实现选框裁剪点云
- UNIPRO Gantt chart "first experience": multi scene exploration behind attention to details
- C language_ Double create, pre insert, post insert, traverse, delete
- 接口自动化测试框架:Pytest+Allure+Excel
- Huawei equipment configuration ospf-bgp linkage
- ROS2安装及基础知识介绍
- UWA pipeline version 2.2.1 update instructions
- Oracle数据库11gr2使用tde透明数据加密报错ora28353,如果运行关闭wallet会报错ora28365,运行打开wallet就报错ora28353无法打开wallet
猜你喜欢
OpenGL ES 学习初识(1)
What is the biggest problem that fresh e-commerce is difficult to do now
数据仓库建设思维导图
ROS2安装及基础知识介绍
Windows Server 2016 standard installing Oracle
At the age of 26, I changed my career from finance to software testing. After four years of precipitation, I have been a 25K Test Development Engineer
UWA Pipeline 2.2.1 版本更新说明
Missing monitoring: ZABBIX monitors the status of Eureka instance
Win10 64 bit Mitsubishi PLC software appears oleaut32 DLL access denied
When my colleague went to the bathroom, I helped my product sister easily complete the BI data product and got a milk tea reward
随机推荐
Oracle数据库11gr2使用tde透明数据加密报错ora28353,如果运行关闭wallet会报错ora28365,运行打开wallet就报错ora28353无法打开wallet
The best way to learn SEO: search engine
At the age of 26, I changed my career from finance to software testing. After four years of precipitation, I have been a 25K Test Development Engineer
leetcode35. 搜索插入位置(简单,找插入位置,不同写法)
PCL实现选框裁剪点云
SEO学习的最好方式:搜索引擎
这个高颜值的开源第三方网易云音乐播放器你值得拥有
UNIPRO Gantt chart "first experience": multi scene exploration behind attention to details
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
顶测分享:想转行,这些问题一定要考虑清楚!
The difference between get and post request types
ROS learning_ Basics
19. Actual memory management of segment page combination
18. Multi level page table and fast table
Hydra common commands
L'auteur est mort? Ai utilise l'art pour conquérir l'humanité
How to reconstruct the class explosion caused by m*n strategies?
3. Business and load balancing of high architecture
1189. Maximum number of "balloons"
Leetcode 78: subset