当前位置:网站首页>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 ,
. ***
边栏推荐
- Vulnhub DC1
- Function analysis of e-commerce website development and construction
- 剑指offer专项突击版第8天
- Influxdb未授权访问&CouchDB权限绕过
- FlinkSQL-UDF自定义数据源
- C language to achieve mine sweeping game
- Network security B module windows operating system penetration test of national vocational college skills competition
- 25. Message subscription and publishing - PubSub JS
- Hcip day 7
- Mitre att & CK ultra detailed learning notes-02 (a large number of cases)
猜你喜欢

Advanced part of C language I. data storage

C language advanced part III. string functions and memory operation functions

Stable TTL serial port rate supported by Arduino under different dominant frequencies

hcip第八天笔记
![[hiflow] Tencent cloud hiflow scene connector realizes intelligent campus information management](/img/a9/7cdab9264902b1e2947a43463f6b32.png)
[hiflow] Tencent cloud hiflow scene connector realizes intelligent campus information management

Sense dimension design responsive layout

Movie recommendation system

Install librosa using Tsinghua image

Harbor2.2 用户角色权限速查

Advanced part of C language IV. detailed explanation of user-defined types
随机推荐
Simple Gateway - intranet server safely obtains external network data
Hcip day 10 notes
R language handwritten numeral recognition
Jenkins detailed deployment
Game three piece chess
Jersey2.25.1 integration freemaker
Facing Tencent (actual combat) - Test Development - detailed explanation of interns (face experience)
Vertex buffer and shader (the cherno + leranopongl) notes
[Huawei] Huawei machine test question-105
Mitre att & CK ultra detailed learning notes-02 (a large number of cases)
Reptile learning - Overview
Hcip 13th day notes
Binary search common questions
The difference between get and post
Selenium basic knowledge automatically login Baidu Post Bar
MySQL statement
The solution of unable to import custom library in pycharm
Anaconda install pytorch
Give a string ① please count the number of times each letter appears ② please print the pair with the most letters
Unable to auto assemble, bean of type "redistemplate" not found