当前位置:网站首页>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
边栏推荐
- Zohocrm deluge function application time verification
- How does yarn link help developers debug NPM packages?
- PostGIS space function
- JS regular case-
- Huawei s5700 switch initialization and configuration SSH and telnet remote login methods
- P2704 [NOI2001] 炮兵阵地(状压dp)
- 创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
- What is definition? What is a statement? What is the difference between them?
- JSON与Object之间转换
- Register keyword
猜你喜欢
![[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)](/img/38/3435d353e50b19fe09c8ab9db52204.png)
[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)

Haproxy+kept cluster setup 02

璞华PLM为全场景产品生命周期管理赋能,助力产品主线的企业数字化转型

Iterm2 setting

C language - Introduction - essence Edition - take you into programming (I)

freetype库的移植

方正锐利重磅升级到12.0版本,包装印前处理更加便捷、高效!

the installer has encountered an unexpected error installing this package

Transplantation of freetype Library

Redis batch startup and shutdown script
随机推荐
Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation
How does yarn link help developers debug NPM packages?
Zohocrm deluge function application time verification
Lua hot update basic grammar
Mutual call between Lua and C #
tslib库的移植
P1896 [scoi2005] non aggression (shape pressure DP)
[cocos creator] get the resource UUID
JS to implement publish and subscribe
Ilruntime learning - start from scratch
Quelle est la définition? Qu'est - ce qu'une déclaration? Quelle est la différence?
Register keyword
Client server model
Retail philosophy retail psychological warfare after reading -- 7-11 is a good product!
【LeetCode】2. Valid parentheses · valid parentheses
Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
JS common basic case sorting (continuous update)
C language - Introduction - essence Edition - take you into programming (I)
unity2019_ Input management
Iterm2 setting