当前位置:网站首页>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 .
边栏推荐
- Before applying data warehouse ODBC, you need to understand these problems first
- Events in JS
- Day45 storage engine data type integer floating point character type date type enumeration and set type constraints table to table relationships
- Set MySQL as externally connectable
- 【音视频】SEI简介
- DOS command virtual environment
- CVPR 2021: learning continuous image representation with local implicit image function
- Inductive bias的一些理解
- Document object
- The first TOF related data set available for deep learning: deep learning for confidence information in stereo and TOF data fusion (iccv 2017)
猜你喜欢

ORACLE DG物理备库使用别名数据文件改变路径到OMF路径
![[ROS] noedic moveit installation and UR5 model import](/img/bc/865c752021a4ee68e963c09f5f632d.png)
[ROS] noedic moveit installation and UR5 model import

全局池化–Pytorch

ESP8266_SNTP(Simple Network Time Protocol)

js基础--关于DOM

Before applying data warehouse ODBC, you need to understand these problems first

Opencv image basic operation (III) -- image feature extraction (corner detection)

ESP8266_SmartConfig
![[image denoising] image denoising based on mean + median + Gauss low pass + various improved wavelet transform, including Matlab source code](/img/df/9c7c9484879249a35781425e710983.jpg)
[image denoising] image denoising based on mean + median + Gauss low pass + various improved wavelet transform, including Matlab source code

Document object
随机推荐
ES6新增特性--箭头函数
js基础--关于DOM
Where is it safer to open an account for soda ash futures? How much do you need to buy at least?
Flask (IV) -- URL construction
New feature in ES6 -- arrow function
CVPR 2021: learning continuous image representation with local implicit image function
Tenthousand words thoroughly learn heap and binary tree
关于CI框架批量导出至压缩文件
js基础--运算符
rac expdp导出时报错:ORA-31693、ORA-31617、ORA-19505
【Objective-C】动态创建控件
Where is it safer to open an account for soda ash futures? How much does it cost to buy at least one hand?
[ROS] noedic moveit installation and UR5 model import
Day41 process pool and thread pool
《1.图书馆里系统》
P4147 "jade toad Palace"
Type-C Bluetooth speaker single port rechargeable OTG solution
RAC expdp export error: ora-31693, ora-31617, ora-19505
Analysis of Kube scheduler disk scheduling source code
面试常问:rem布局,flex布局等