当前位置:网站首页>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 .
边栏推荐
猜你喜欢

Express framework

invalid syntax

MySQL data type

新媒体运营策略(以小红书为例)帮助你快速掌握爆款创作方法

单元测试,写起来到底有多痛?

武汉理工大学第三届程序设计竞赛 B-拯救DAG王国(拓扑性质处理可达性统计问题)

Dom and events

Summary 1 - deep learning - basic knowledge learning

Matrixcube unveils the complete distributed storage system matrixkv implemented in 102-300 lines

Von Neumann architecture
随机推荐
1000 okaleido tiger launched binance NFT, triggering a rush to buy
2020-09-17
Floating effect and characteristics
Simple setting method of search box
Why is Google's internal tools not suitable for you?
Ribbon execution logic source code analysis
Deep recursion, deep search DFS, backtracking, paper cutting learning.
Vs2019 WinForm clr20r3 error
QVariant的使用
[training day13] Internet [concurrent search]
[training day15] paint road [minimum spanning tree]
Qt5.12 installation error prompt: c:\qt5.12.11\vcredist\vcredist_ msvc2019_ x86.exe /norestart /q
【集训DAY13】Out race【数学】【动态规划】
自媒体人必备的4个资源工具,每一个都很实用
Summary of traversal methods of six sets list, set, map, queue, deque and stack
The fourth experiment nat
Hcie is finally in hand, and the road begins
HCIE终到手,路才开始
What are the differences between FileInputStream and bufferedinputstream?
Network security and level protection