当前位置:网站首页>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
边栏推荐
- Oracle database 11gr2 uses TDE transparent data encryption to report an error ora28353. If you run to close the wallet, you will report an error ora28365. If you run to open the wallet, you will repor
- Introduction to ros2 installation and basic knowledge
- 18. Multi level page table and fast table
- 【每日一题】729. 我的日程安排表 I
- 这个高颜值的开源第三方网易云音乐播放器你值得拥有
- Internal and external troubles of "boring ape" bayc
- 编译,连接 -- 笔记 -2
- Librosa audio processing tutorial
- The difference between get and post request types
- After working for 10 years, I changed to a programmer. Now I'm 35 + years old and I'm not anxious
猜你喜欢
After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.
医疗软件检测机构怎么找,一航软件测评是专家
kubernetes集群搭建Zabbix监控平台
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models. common‘ from ‘/home/yolov5/models/comm
树莓派3B更新vim
Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
What is the biggest problem that fresh e-commerce is difficult to do now
UWA pipeline version 2.2.1 update instructions
How to find a medical software testing institution? First flight software evaluation is an expert
《从0到1:CTFer成长之路》书籍配套题目(周更)
随机推荐
You deserve this high-value open-source third-party Netease cloud music player
Introduction to ros2 installation and basic knowledge
Idea console color log
[daily question] 729 My schedule I
Configure raspberry pie access network
Database basics exercise part 2
接口自动化测试框架:Pytest+Allure+Excel
Pymongo gets a list of data
Simple use of MySQL database: add, delete, modify and query
Latex文字加颜色的三种办法
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm
After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.
因高额网络费用,Arbitrum 奥德赛活动暂停,Nitro 发行迫在眉睫
前缀和数组系列
Leetcode35. search the insertion position (simple, find the insertion position, different writing methods)
kubernetes集群搭建Zabbix监控平台
leetcode1020. 飞地的数量(中等)
这个高颜值的开源第三方网易云音乐播放器你值得拥有
Raspberry pie serial port login and SSH login methods
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