当前位置:网站首页>abstract class
abstract class
2022-07-24 07:45:00 【Glunn】
Preface
occasionally , Base classes are not related to specific things , But only express an abstract concept , It is used to provide a public interface for its derived classes . So ,C# Abstract classes are introduced in (abstract class) The concept of .
Abstract class cannot be instantiated . The purpose of abstract classes is to provide a common base class definition that can be shared by multiple derived classes . for example , A class library can define an abstract class , Use it as an argument to multiple class library functions , And ask the programmers who use the library to provide their own class implementation by creating derived classes . Abstract classes can also define abstract methods . The method is to put the keyword abstract Add to the front of the return type of the method .
keyword
1 keyword :abstract: abstract
2 from abstract A modified class is called an abstract class , from abstract The method of modification is called abstract method .
3 If there are abstract methods in a class , The class must be abstract .
4 Abstract method : If a method is an abstract method , The method must be in an abstract class . At the same time, abstract methods only have method declarations , There is no way to achieve . Abstract methods are implemented by subclasses that inherit abstract classes , That is, if a class inherits an abstract class , This class must implement all abstract methods in the abstract class . Rewrite abstract methods with override.
5 Abstract classes cannot instantiate objects .
Use abstract keyword public abstract bool Withdraw(…);
Abstract methods are methods that must be overridden by derived classes .
Abstract methods can be regarded as virtual methods without implementers
If the class contains abstract methods , Then class must be defined as abstract class , Whether or not other general methods are included
Virtual method
Use virtual keyword public virtual bool Withdraw(…);
Both virtual and abstract methods can be overridden by derived classes , What's the difference between them ?
- Virtual methods must have an implementation part , The abstract method does not provide the implementation part , Abstract methods are methods that force derived class coverage , Otherwise, the derived class will not be instantiated .
- Abstract methods can only be declared in abstract classes , The virtual method is not . In fact, if the class contains abstract methods , Then the class is also abstract , Must also be declared abstract .
- Abstract methods must be overridden in derived classes ,
. ***
边栏推荐
- 2021-06-03 database query - sorting
- Movie recommendation system
- Buffer overflow vulnerability of network security module B in national vocational college skills competition
- Appium use
- requests-爬虫多页爬取肯德基餐厅位置
- About how to set colored fonts on the terminal
- numpy.inf
- 爬虫学习-概述
- 2022-07-23:给定N件物品,每个物品有重量(w[i])、有价值(v[i]), 只能最多选两件商品,重量不超过bag,返回价值最大能是多少? N <= 10^5, w[i] <= 10^5, v
- Requests crawl page source code data
猜你喜欢

Oauth2==sso three protocols. Oauth2 four modes

2021-06-03pip error valueerror: unable to find resource t64.exe in package pip_ vendor.distlib

Jackson 解析 JSON 详细教程

觉维设计响应式布局

MS SQL Server 2019 学习

Injectfix principle learning (to realize the heat of repair addition)

Hcip 13th day notes

Installation and use of Zen path & defect report & defect operation

Sense dimension design responsive layout

C语言文件操作
随机推荐
MS SQL Server 2019 learning
【Pytorch】nn.Module
Source code analysis of Nacos configuration center
Facing Tencent (actual combat) - Test Development - detailed explanation of interns (face experience)
PHP link log scheme
Selenium basic knowledge debugging method
MS SQL Server 2019 学习
Collection of sorting topics
System integration project management engineer (soft test intermediate) key knowledge, recitation version
爬虫学习-概述
C language file operation
Sense dimension design responsive layout
The solution of unable to import custom library in pycharm
Li Kou, niuke.com - > linked list related topics (Article 1) (C language)
25. Message subscription and publishing - PubSub JS
XSS vulnerability learning
【Pytorch】Dataset_ DataLoader
Starting from scratch C language intensive Part 3: Functions
Flinksql UDF custom data source
【云原生】MySql索引分析及查询优化