当前位置:网站首页>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 .
边栏推荐
- Mocha test
- Qt的TQTreeWidget控件
- DHCP first static experiment
- Select structure if branch structure
- 1000 okaleido tiger launched binance NFT, triggering a rush to buy
- [training day13] out race [mathematics] [dynamic planning]
- [training day15] paint road [minimum spanning tree]
- Day 3 experiment
- Websocket summary
- QVariant的使用
猜你喜欢

Binder原理

Dom and events
![[training day13] backpack [dynamic planning] [greed]](/img/a7/3df395d84f510dea8b42ebcc4ff5f2.png)
[training day13] backpack [dynamic planning] [greed]

recyclerview计算滑动距离之computeHorizontalScrollExtent-computeHorizontalScrollRange-computeHorizontalScrol

DHCP first static experiment

Tree view model example of QT

CUDA environment construction

Kibana~后台启动Kibana之后无法找到进程号

Mocha test

Interview question 17.11. word distance ●●
随机推荐
LabVIEW develops PCI-1680U dual port can card
XSS collect common code
【集训DAY12】X equation 【高精度】【数学】
Madness. MySQL learning.
Anaconda~Upload did not complete.
Why is Google's internal tools not suitable for you?
Qtreewidget control of QT
【集训DAY15】简单计算【树状数组】【数学】
[training Day12] min ratio [DFS] [minimum spanning tree]
Array中可以用泛型吗
MatrixCube揭秘102——300行实现的完整分布式存储系统MatrixKV
Severely crack down on illegal we media operators according to law: it is urgent to purify the we media industry
ECMA 262 12 Lexical Grammer
The third programming competition of Wuhan University of technology b- save the kingdom of DAG (topological properties deal with accessibility Statistics)
Session and cookie, token and storage
Anaconda~Upload did not complete.
BIO、NIO、AIO的区别?
汇编语言与微机原理实验一、实验二、实验三:分支程序设计/循环程序设计/子程序设计
Compiler introduction
The difference between "rewrite" and "overload"