当前位置:网站首页>What is the difference between an interface and an abstract class?
What is the difference between an interface and an abstract class?
2022-06-11 09:45:00 【Six years of Surabaya】
The difference between interface and abstract class ?
Let me first talk about the two of them Grammatical differences Well , Then let's talk about my personal understanding .
- Abstract classes can have specific methods and properties , Interfaces can only have abstract methods and constants .
- Abstract class use abstract modification , Interface to use interface modification
- A class can only inherit one class , But you can implement multiple interfaces .
- Abstract classes can have either ordinary methods or abstract methods , Interfaces are full of abstract methods ,JDK1.8 There can also be specific methods in the interface of , But you have to use static Or is it default To modify .
- The default modifier of all methods in the interface is public abstract, The default modifier for member variables in the interface is pulbic static final.
What I just said is the grammatical difference between interfaces and abstract classes , Now let me talk about some of my Personal understanding .
Abstract is actually relative to concrete objects , Matianle , Man , human beings , biological , The higher the level of abstraction , The wider the coverage , The less it means .
Abstract classes are mainly used to abstract classes , Interface is mainly used to abstract functions . To put it bluntly, the abstract class represents what the object is . The interface represents what the object can do . For example, there are men and women , Their abstract class is human . explain , They're all human . People can eat , Cats can also eat , At this time you can put “ Eat something ” Defined as an interface , Then let these classes implement it . as for When to use abstract classes , When to use interfaces , My understanding is to see whether there is common business logic among multiple subclasses , If there are any, use abstract classes and put these logic into the abstract classes , Otherwise, use the interface .
边栏推荐
- jedisLock—redis分布式锁实现
- MySQL:Got a packet bigger than ‘max_ allowed_ packet‘ bytes
- 整型提升例题
- ESP8266_通过MQTT协议连接阿里云
- Identifier keyword literal data type base conversion character encoding variable data type explanation operator
- 我们是如何连上WiFi的?
- rac expdp导出时报错:ORA-31693、ORA-31617、ORA-19505
- ESP8266_GET请求天气预报、json解析
- Jmeter的使用(模拟高并发)
- 【Objective-C】‘NSAutoreleasePool‘ is unavailable: not available in automatic reference counting mode
猜你喜欢
随机推荐
OpenSSL usage
CVPR 2021: learning continuous image representation with local implicit image function
CVE-2021-40449 NtGdiResetDC UAF
Interview question 17.10 Main elements
Analysis of Kube scheduler disk scheduling source code
全局池化–Pytorch
Day39 content summary
Output image is bigger (1228800b) than maximum frame size specified in properties (1048576b)
【ROS】noedic-moveit安装与UR5模型导入
The ins-30131 installer failed to verify the required initial settings
整型提升例题
oracle 11g rac 磁盘组有空间无法增加数据文件?
Flask (IV) -- URL construction
Set MySQL as externally connectable
ESP8266_ Get request weather forecast and JSON parsing
How do online app stores of laundry chain stores do?
JS foundation -- Operator
Day45 storage engine data type integer floating point character type date type enumeration and set type constraints table to table relationships
不同CV任务的标注类型
12.5 concurrent search + violent DFS - [discovery ring]









