当前位置:网站首页>Abstract classes and interfaces
Abstract classes and interfaces
2022-07-03 08:05:00 【Luckyᕙ(⇀‸↼‵‵)ᕗ】

One . abstract class
1、 Definition
Why:
Calculator class ( Parent class ) There are four functions of addition, subtraction, multiplication and division , But very subclasses inherit , Some methods have been rewritten by themselves , At this time, the functions of these methods in the parent class are meaningless . So some methods don't need to be implemented , Just declare ( Abstract method ).
abstract class (what): A class is an abstraction with the same characteristics and behavior , And the abstract class (class with abstract) Didn't point out the specific details of the behavior , And its subclasses implement the corresponding behavior .
Add a before the general class abstract Keywords are abstract classes .
A class containing one or more abstract methods
3、 The abstract class features :
1、 Cannot create an instance of an abstract class .(//Father f = new Father();Father Parent class )
2、 By placing keywords before class definitions sealed, You can declare a class as a sealed class . When a class is declared sealed when , It cannot be inherited . An abstract class cannot be declared sealed.
4、 Abstract method characteristics :
1、 Abstract methods have no method bodies
2、 Abstract methods must be in abstract classes
3、 Abstract methods must be implemented in subclasses , Unless the subclass is an abstract class
Two . Interface
C: Process oriented
C#、java、C++: object-oriented
1. Definition
C# Whether multiple inheritance is supported ?
yes . Classes can only be inherited singly , Interfaces support multiple inheritance
Why:
Interface : Designate a group of Method Members without implementing their reference types
Used to describe a set of common methods ( attribute ), There is no implementation of the method
Defining methods cannot add any access modifiers , Default public . You cannot add static static
What can be defined : Method , attribute , event , Indexer
Undefined content : Field , operator overloading , instant constructor , Destructor
There is an inheritance relationship between classes ( use :( The colon )), The relationship between classes and interfaces is implementation ( use :( The colon ))
2. Implicit call : There is no method to specify which interface to implement Single interface Classes and interfaces can access methods
Display call : Class implements multiple interfaces , And the interface contains methods with the same signature It can only be accessed through the interface
3. Interface features
1、 Interfaces cannot be instantiated
2、 The implementation class must implement all methods of the interface
3、 Implementation classes can implement multiple interfaces
4、 Variables in an interface are static constants
4. The difference between abstract classes and interfaces
1. The keywords used are different Can't instantiate , Implement methods through inheritance
2. Interface support ” Multiple inheritance “, Abstract classes cannot implement
3. The definition content and method are different
4. Interface supports callback , Abstract classes cannot , Because inheritance doesn't support
5. Abstract classes need to use override Realization
边栏推荐
- Redis批量启停脚本
- Usage of (case, when) in PostgreSQL
- Iterm2 setting
- P2704 [NOI2001] 炮兵阵地(状压dp)
- Redis view client connection
- 2020-12-12
- Haproxy+kept cluster setup 02
- Zohocrm deluge function application time verification
- P2622 关灯问题II(状态压缩 搜索)
- Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task
猜你喜欢

haproxy+keepalived搭建01

Redis批量启停脚本

Transplantation of freetype Library

数据库应用技术课程设计之商城管理系统

Scite change background color
![[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December](/img/51/81ceaf8746ec7455ea8abf9f038e81.jpg)
[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December

PostGIS space function

一条通往服务器所有端口的隧道

Haproxy+kept cluster setup 02

璞华PLM为全场景产品生命周期管理赋能,助力产品主线的企业数字化转型
随机推荐
Static keyword
the installer has encountered an unexpected error installing this package
JS regular case-
IP production stream is so close to me
How does yarn link help developers debug NPM packages?
Haproxy+kept build 01
Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
Idea unreference Display Effect
haproxy+keepalived搭建01
Product creation and commercial realization of chat robot (according to La Ma Bang - Dr. Wang Jingjing - speech)
E: 无法定位软件包 ros-melodic-desktop-full
RM delete file
Worldview satellite remote sensing image data / meter resolution remote sensing image
What to do after the browser enters the URL
Idea dereference display effect
Huawei s5700 switch initialization and configuration Telnet, SSH user methods
unity2019_ Input management
Redis view client connection
Youyou1 of xlua knapsack system
Technical dry goods | thinking about the unification of dynamic and static diagrams of AI framework