当前位置:网站首页>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
边栏推荐
- [cocos creator] Click the button to switch the interface
- WorldView卫星遥感影像数据/米级分辨率遥感影像
- Transfinite hacker cognition
- Technical dry goods | some thoughts on the future of AI architecture
- 使用 FileChannel 进行文件的复制拷贝
- C language - Introduction - essence Edition - take you into programming (I)
- [end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
- What does (+) in Oracle mean
- 数据库应用技术课程设计之商城管理系统
- haproxy+keepalived搭建01
猜你喜欢

Screenshot tool snipaste

STM32F103 SPI (pit Diary)

An article for you to understand - Manchester code

Wechat applet taro learning record

Viz artist advanced script video tutorial -- stringmap use and vertex operation

CLion-Toolchains are not configured Configure Disable profile问题解决

Lua framwrok framework starts
![[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18](/img/9b/db5fe1a37e0de5ba363f9e108310a5.png)
[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18

LwIP learning socket (application)

Install cross compiler arm none liunx gnueabihf
随机推荐
Screenshot tool snipaste
Conversion between JSON and object
Idea unreference Display Effect
Storage of data
JSON与Object之间转换
Compilation error: "not in executable format: file format not recognized"“
Huawei s5700 switch initialization and configuration Telnet, SSH user methods
WPF:解决MaterialDesign:DialogHost 无法关闭问题
[global product discovery 2] the first pure cloud augmented reality (AR) platform - Israel
【cocos creator】点击按钮切换界面
How to configure GDAL under idea
P2622 关灯问题II(状态压缩 搜索)
Free use until 2015 -- viz artist multi touch plug-in package
Client server model
PHP wechat red packet grabbing algorithm
[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
Xlua task list youyou
[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)
Huawei switches are configured with SSH login remote management switches
haproxy+keepalived搭建01