当前位置:网站首页>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
边栏推荐
- IP production stream is so close to me
- register关键字
- Unity performance optimization
- [cocos creator] get the resource UUID
- Mutual call between Lua and C #
- 一条通往服务器所有端口的隧道
- The difference between hdmi2.1 and hdmi2.0 and the conversion of PD signals.
- Wechat native applet cloud development learning record 01
- Quality blog——
- [at] ABC 258g - Triangle triples reachable - violence
猜你喜欢
Unity2019_ Lighting system
Screenshot tool snipaste
Oracle insert single quotation mark
Wpf: solve the problem that materialdesign:dialoghost cannot be closed
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
MAE
Xlua task list youyou
Free use until 2015 -- viz artist multi touch plug-in package
Shader foundation 01
Haproxy+kept build 01
随机推荐
Demonstration of plug-in use of ventuz basic series
Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico
PHP wechat red packet grabbing algorithm
Oracle queries grouped by time
什么是数据类型?数据类型有什么用?
链式长取值
Multi traveling salesman problem -- overview of formula and solution process
freetype库的移植
Mutual call between Lua and C #
Are you still watching the weather forecast on TV?
Unity one click AssetBundle
Unity2019_ Lighting system
idea取消引用显示效果
How to configure GDAL under idea
Xlua task list youyou
*p++、*++p、++*p、(*p)++
[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)
一个实习生的CnosDB之旅
Quality blog——
[MySQL 13] if you change your password for the first time after installing mysql, you can skip MySQL password verification to log in