当前位置:网站首页>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边栏推荐
- Depth residual network
- What is the biggest problem that fresh e-commerce is difficult to do now
- TS Basics
- A method to measure the similarity of time series: from Euclidean distance to DTW and its variants
- 3. Business and load balancing of high architecture
- SEO学习的最好方式:搜索引擎
- [daily question] 729 My schedule I
- Call, apply, bind rewrite, easy to understand with comments
- The psychological process from autojs to ice fox intelligent assistance
- 【服务器数据恢复】IBM服务器raid5两块硬盘离线数据恢复案例
猜你喜欢

ROS学习_基础

Kubernetes cluster builds ZABBIX monitoring platform

Internal and external troubles of "boring ape" bayc

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

开源的网易云音乐API项目都是怎么实现的?

Configure raspberry pie access network

leetcode1020. Number of enclaves (medium)

leetcode6109. 知道秘密的人数(中等,周赛)

Establishment and operation of cloud platform open source project environment

1091: two or three things in childhood (multi instance test)
随机推荐
Win10 64 bit Mitsubishi PLC software appears oleaut32 DLL access denied
1091: two or three things in childhood (multi instance test)
hydra常用命令
leetcode704. Binary search (find an element, simple, different writing)
微信脑力比拼答题小程序_支持流量主带最新题库文件
leetcode704. 二分查找(查找某个元素,简单,不同写法)
从autojs到冰狐智能辅助的心里历程
Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
Visitor tweets about how you can layout the metauniverse
LeetCode Algorithm 2181. Merge nodes between zero
Entity Developer数据库应用程序的开发
《从0到1:CTFer成长之路》书籍配套题目(周更)
JDBC学习笔记
Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
[server data recovery] case of offline data recovery of two hard disks of IBM server RAID5
BUU的MISC(不定时更新)
呆错图床系统源码图片CDN加速与破解防盗链功能
【每日一题】729. 我的日程安排表 I
Kubernetes cluster builds ZABBIX monitoring platform
SEO学习的最好方式:搜索引擎