当前位置:网站首页>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
边栏推荐
- Bio model realizes multi person chat
- 配置树莓派接入网络
- Huawei equipment configuration ospf-bgp linkage
- Yield method of tread
- 中青看点阅读新闻
- 升级版手机检测微信工具小程序源码-支持多种流量主模式
- 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
- 19. Actual memory management of segment page combination
- How to find a medical software testing institution? First flight software evaluation is an expert
- After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.
猜你喜欢
Due to high network costs, arbitrum Odyssey activities are suspended, and nitro release is imminent
Leetcode59. spiral matrix II (medium)
Introduction to ros2 installation and basic knowledge
Cookie Technology & session Technology & ServletContext object
Attributeerror: can 't get attribute' sppf 'on < module' models. Common 'from' / home / yolov5 / Models / comm
Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
leetcode1020. Number of enclaves (medium)
微信公众号无限回调授权系统源码 全网首发
[server data recovery] case of offline data recovery of two hard disks of IBM server RAID5
Configure raspberry pie access network
随机推荐
Interface automation test framework: pytest+allure+excel
Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
The author is dead? AI is conquering mankind with art
UWA Pipeline 2.2.1 版本更新说明
leetcode35. 搜索插入位置(简单,找插入位置,不同写法)
Simple use of MySQL database: add, delete, modify and query
顶测分享:想转行,这些问题一定要考虑清楚!
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
Oracle数据库11gr2使用tde透明数据加密报错ora28353,如果运行关闭wallet会报错ora28365,运行打开wallet就报错ora28353无法打开wallet
How to find a medical software testing institution? First flight software evaluation is an expert
TS Basics
【Hot100】739. Daily temperature
idea控制台彩色日志
The best way to learn SEO: search engine
leetcode1020. 飞地的数量(中等)
简单描述 MySQL 中,索引,主键,唯一索引,联合索引 的区别,对数据库的性能有什么影响(从读写两方面)
呆错图床系统源码图片CDN加速与破解防盗链功能
Call, apply, bind rewrite, easy to understand with comments
Yield method of tread
18.多级页表与快表