当前位置:网站首页>The difference between abstract classes and interfaces
The difference between abstract classes and interfaces
2022-07-25 22:51:00 【Exposed cotton】
abstract class :(Abstract)
1, Concept : If a class defines a method , But there is no specific code to execute , Then this method is called abstract method , For abstract methods abstract To modify , Because the abstract method cannot be executed , Then this class is also called abstract class . use abstract The decorated class is an abstract class .
eg1:
// abstract class
abstract class Person {
// Abstract method
public abstract void say();
}
characteristic :1. Abstract classes are not instantiated
eg2:Person p = new Person(); // Compile error
2. Abstract methods have no cube
eg3:public abstract void run();
Interface :
1, Concept : Interface is an abstraction of behavior , It's a collection of abstract methods , Using interfaces can achieve the purpose of architectural design of separating behavior definition and business implementation , And the multiple implementation and multiple inheritance of the interface , More flexible in architecture design , Easy to expand . An interface is a pure abstract code structure that is more abstract than an abstract class , Cannot contain member variables , Contains only constants , Abstract method , Default method, etc .
difference :
1. Defining abstract methods in an interface can be done without abstract keyword , And the abstract method must add .
2. There are no ordinary methods in the interface , Construction method not allowed , Declared constants cannot be modified , And abstract classes can have ordinary methods , Allow construction methods , You can define member variables .
3. Multiple inheritance is allowed in the interface , Use implements Multiple interfaces , An abstract class can only inherit one class .
4. Can only be used in the interface public Access modifier , Abstract classes can use arbitrary access modifiers .
边栏推荐
- Simple setting of drop-down triangle
- Summary 1 - deep learning - basic knowledge learning
- 3 lexical analysis
- Multi data source switching
- Naming rules of software test pytest pytest the pre and post confitest of use cases Py customized allure report @pytest.mark.parameter() decorator as data-driven
- ribbon 执行逻辑源码解析
- (1) DDL, DML, DQL, DCL and common data types
- Node.js operation database
- Document flow definition, box model related knowledge
- Matrixcube unveils the complete distributed storage system matrixkv implemented in 102-300 lines
猜你喜欢

The third programming competition of Wuhan University of technology b- save the kingdom of DAG (topological properties deal with accessibility Statistics)

【集训DAY13】Out race【数学】【动态规划】

【自然语言处理】【向量表示】AugSBERT:改善用于成对句子评分任务的Bi-Encoders的数据增强方法

JVM memory area

Express framework

Session and cookie, token and storage

CMU AI PhD first year summary

Tree view model example of QT

自媒体人必备的4个素材网站,再也不用担心找不到素材

Day006 select structure (if statement exercise)
随机推荐
[文献阅读] - HRL -[HRL with Universal Policies for Multi-Step Robotic Manipulation]
[training day13] Internet [concurrent search]
关于getchar和scanf的使用示例及注意点
[training Day12] min ratio [DFS] [minimum spanning tree]
Kibana~ the process number cannot be found after kibana is started in the background
Ribbon execution logic source code analysis
Day 3 experiment
Opencv compile and call GPU version
Interview question 17.11. word distance ●●
【集训DAY11】Calc【数学】
Today, I sorted out some problems about high collapse
ribbon 执行逻辑源码解析
CMU AI PhD 第一年总结
CSV intro
【集训DAY15】简单计算【树状数组】【数学】
Vodak software: Smart City solution
新媒体运营策略(以小红书为例)帮助你快速掌握爆款创作方法
【集训DAY15】好名字【hash】
We media people must have four resource tools, each of which is very practical
3 lexical analysis