当前位置:网站首页>Abstract classes and interfaces
Abstract classes and interfaces
2022-07-29 05:33:00 【Xiao Hong is working hard】
List of articles
abstract class , Abstract method , Summary of the interface
Abstract method | abstract class | Interface |
---|---|---|
Abstract methods have no method bodies , Give it to the subclass implementation | Abstract classes do not necessarily have static methods , Those with static methods must be abstract classes . | JDK1.8 Before : Only method declarations can be written in interfaces , Instead of writing the specific implementation of the method JDK1.8 after : Interfaces can write specific implementations of method declarations . |
Abstract method modifiers It can't be private,final,static( Because subclass implementation is required ). | Can't be instantiated , Can only be inherited . | There is no constructor in the interface , Can't be instantiated . |
Abstract methods must be defined in abstract classes or interfaces . | Subclasses of abstract classes may not implement all abstract methods , But it must also be an abstract class .( Abstract derived classes ) | Interfaces can only inherit interfaces , Can't inherit class , Interface supports multiple inheritance . |
nothing | The constructor of an abstract class cannot be defined as private .( The subclass constructor will call the parent constructor .) | The member variables defined in the interface are... By default public static final Modified static constants |
nothing | Abstract class cannot be defined as final,final ( Modified classes cannot be inherited ). | Methods in interfaces : The default is public abstract An abstract method of embellishment . JDK1.8 There cannot be static methods before , There can be no ordinary way . JDK1.8 After that, there can be static methods , There can be a common way . |
nothing | Abstract classes can implement interfaces , You can inherit concrete classes , You can also inherit abstract classes . | Internal classes defined in interface , The default is public static Decorated static inner class . |
nothing | There are common methods in abstract classes , You can also have static methods . | nothing |
Similarities and differences between abstract classes and interfaces :
The same thing | Difference |
---|---|
① Abstract classes and interfaces cannot be instantiated | ① Abstract classes have construction methods , Interface has no constructor |
② Abstract classes and interfaces can define abstract methods , Subclass / The implementation class must override these abstract methods | ② Abstract classes can contain ordinary methods , The interface can only be public abstract Modify abstract methods (Java8 After that you can ) |
nothing | ③ Abstract class can only inherit only , Interfaces can inherit more |
nothing | ④ Abstract classes can define various types of member variables , The interface can only be public static final Modified static constants |
nothing | ⑤ The access type of an abstract method in an abstract class can be public,protected and ( Default type , although eclipse Do not report wrong , But it should not ), But an abstract method in an interface can only be public Type of , And the default is public abstract type . |
nothing | ⑥ Static methods can be included in abstract classes , Static methods cannot be included in an interface . |
Thank an unknown blogger for his summary , In this blog, I learned a lot from each other's summary knowledge points : Portal
边栏推荐
- Thousands of databases, physical machines all over the country, JD logistics full volume cloud live record | interview with excellent technical team
- Detailed explanation of exit interrupt
- 浅谈Servlet
- 167. 两数之和 II - 输入有序数组
- Occt learning 001 - Introduction
- ClickHouse学习(六)语法优化
- MySQL的详细安装使用教程(保姆式安装图文讲解)
- 【C语言系列】— 一道递归小题目
- QML type: state state
- Helm chart for Kubernetes
猜你喜欢
Live broadcast preview | how to save 30% labor cost and shorten 80% trademark processing cycle?
【C语言系列】—文件操作详解(上)
More than 200 ISVs have settled in! The first anniversary of Alibaba cloud computing nest
Application of Huffman tree and Huffman coding in file compression
Occt learning 002 - environment construction
C语言数组入门到精通(数组精讲)
Redirection and files
Occt learning 001 - Introduction
Detailed explanation of GPIO input and output
【剑指offer】— 详解库函数atoi以及模拟实现atoi函数
随机推荐
QT learning: qdropevent drag event
Introduction to array learning simple question sum of two numbers
redis的基本使用
End of document
实现简单的数据库查询(不完整)
ClickHouse学习(八)物化视图
JD cloud and Forrester consulting released a hybrid cloud report that cloud Nativity has become a new engine driving industrial development
JD cloud golden autumn cloud special offer is in progress! Code scanning participation activities
Best practices for elastic computing in the game industry
科班同学真的了解未来的职业规划吗?
Day 5
第一周总结
Day 5
C language file operation
VIM editor use
英伟达周锡健:设计到数字营销的最后一公里
省市区三级联动(简单又完美)
重定向和文件
Best practices of JD cloud Distributed Link Tracking in financial scenarios
One dimensional array exercise