当前位置:网站首页>C - Inheritance - polymorphism - virtual function member (lower)
C - Inheritance - polymorphism - virtual function member (lower)
2022-07-06 07:07:00 【Tsim Sha Tsui duankun 415】
Create a method , Then the parameter is our parent class Animal( When you pass it in, you should pass it to the parent class , Otherwise, if the parent class is passed in later , When calling, the subclass has some features, and the parent class does not necessarily have )
public static void Display(Animal animal)
{
System.Console.WriteLine(animal.Name);
}
And then, when called ,dog and cat All are Animal Subclasses of ,new Two objects
dog peachas = new dog();
cat egg = new cat();
When we call a method , You can pass in the subclass object
Because the subclass has all the functional features of the parent class , So parameters can be subclasses
Display(peachas);
Display(egg);
In the last article is Supplement of operators
One or two lines are equivalent to the abbreviation of the writing in the lower right corner
s This is a new variable , Give him a display conversion , This quoted s Variables can be used immediately
virtual
Marked as virual Functions of can be overridden by subclasses , Including method , Indexer , attribute , event
public class Animal
{
public string Name;
public virtual decimal Liability => 0;
}
Then the subclass should override the parent class with override Modifier
public class Egg : Animal { public long sharesOwbed; }
public class ass : Animal
{
public double mansion;
public override decimal Liability => (decimal)mansion;
}
Make a down conversion
ass mansion = new ass
{mansion = 2500 };
Animal a = mansion;
Console.WriteLine(mansion.Liability);
Console.WriteLine(a.Liability);
Both results are 2500
边栏推荐
- What is the biggest problem that fresh e-commerce is difficult to do now
- How to reconstruct the class explosion caused by m*n strategies?
- Win10 64 bit Mitsubishi PLC software appears oleaut32 DLL access denied
- C语言_双创建、前插,尾插,遍历,删除
- 顶测分享:想转行,这些问题一定要考虑清楚!
- RichView TRVStyle 模板样式的设置与使用
- Proteus -- Serial Communication parity flag mode
- Zhongqing reading news
- UNIPRO Gantt chart "first experience": multi scene exploration behind attention to details
- 编译,连接 -- 笔记 -2
猜你喜欢
19.段页结合的实际内存管理
1091: two or three things in childhood (multi instance test)
Raspberry pie serial port login and SSH login methods
Entity Developer数据库应用程序的开发
Supporting title of the book from 0 to 1: ctfer's growth road (Zhou Geng)
医疗软件检测机构怎么找,一航软件测评是专家
Proteus -- Serial Communication parity flag mode
leetcode1020. Number of enclaves (medium)
基于PyTorch和Fast RCNN快速实现目标识别
Practical guidance for interface automation testing (Part I): what preparations should be made for interface automation
随机推荐
leetcode841. Keys and rooms (medium)
[advanced software testing step 1] basic knowledge of automated testing
leetcode35. 搜索插入位置(简单,找插入位置,不同写法)
Cif10 actual combat (resnet18)
supervisor 使用文档
Wechat official account infinite callback authorization system source code, launched in the whole network
作者已死?AI正用艺术征服人类
Embed UE4 program into QT interface display
配置树莓派接入网络
【JDBC】快速入门教程
Raspberry pie serial port login and SSH login methods
Bitcoinwin (BCW): the lending platform Celsius conceals losses of 35000 eth or insolvency
【Hot100】739. Daily temperature
巴比特 | 元宇宙每日必读:中国互联网企业涌入元宇宙的群像:“只有各种求生欲,没有前瞻创新的雄心”...
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
[server data recovery] case of offline data recovery of two hard disks of IBM server RAID5
因高额网络费用,Arbitrum 奥德赛活动暂停,Nitro 发行迫在眉睫
Refer to how customer push e-commerce does content operation
leetcode841. 钥匙和房间(中等)
Librosa audio processing tutorial