当前位置:网站首页>Abstract classes and interfaces
Abstract classes and interfaces
2022-06-12 09:25:00 【BD without effort】
One 、 abstract class
abstract The class modified by keyword is called abstract class , The decorated method is called abstract method , Abstract methods only have the declaration of methods , There is no method body . It cannot be instantiated , Can only be used as a superclass of subclasses . Abstract classes are templates used to create subclasses at the inheritance level .
characteristic
1、 Abstract class cannot be instantiated ( Out of commission new Keyword instantiation object ), Can only be inherited ;
2、 What contains abstract methods must be abstract classes , But abstract classes don't necessarily have abstract methods ;
3、 The modifier of an abstract method can only be public perhaps protected, The default is public;
4、 Abstract methods in abstract classes are only method declarations , There is no way to achieve ;
5、 Subclasses override superclasses ( abstract class ) All the abstract methods of , Then the subclass is a class , Otherwise, it is still an abstract class ;
6、 Abstract classes can contain properties 、 Method 、 Construction method , The goal is for subclasses to call .
Two 、 Interface
An interface is a declaration of a series of methods , Is a collection of method features , An interface has only the characteristics of a method, but no method implementation , So these methods can be implemented by different classes in different places , And these implementations can have different behaviors ( function ).
characteristic
1、 Interfaces can contain variables 、 Method ; The variable is implicitly specified as public,static,final, Method is implicitly specified as public,abstract(JDK1.8 Before );
2、 Interface supports multiple inheritance , That is, an interface can extends Multiple interfaces , Indirectly solved Java Single inheritance of classes in ;
3、 A class can implement multiple interfaces ;
4、JDK1.8 New features have been added to the interface :
4.1、 The default method (default method):JDK 1.8 Allows you to add non abstract method implementations to an interface , But must use default Keyword modification ; Defined default Methods can be implemented without subclasses , But it can only be called by the object implementing the subclass ; If a subclass implements multiple interfaces , And these interfaces contain the same default methods , The subclass must override the default method ;
4.2、 Static methods (static method):JDK 1.8 Allowed in static Keyword modifies a method , And provide implementation , Called interface static methods . Interface static methods can only be called through interfaces ( The interface name . Static method name ).
3、 ... and 、 Similarities between abstract classes and interfaces
1、 Can't be instantiated .
2、 The implementation class of an interface or subclass of an abstract class can only be instantiated after the method in the interface or abstract class is implemented .
Four 、 The difference between abstract classes and interfaces
1. Abstract class should be inherited by subclass , Interface to be implemented by class .
2. Interface can only make method declaration , Method declaration can be made in abstract classes , It can also be realized by methods .
3. The variables defined in the interface can only be public static constants , Variables in an abstract class are ordinary variables .
4. Interface is the result of design , Abstract classes are the result of refactoring .
5. Abstract classes and interfaces are used to abstract concrete objects , But the interface has the highest level of abstraction .
6. Abstract classes can have specific methods and properties , Interfaces can only have abstract methods and immutable constants .
7. Abstract classes are mainly used to abstract classes , Interface is mainly used to abstract functions .
8. There are construction methods in abstract classes , There is no constructor in the interface .
边栏推荐
- Auto.js学习笔记9:脚本引擎使用,启动指定路径脚本文件和关闭等基础方法
- Summary of APP test interview questions, which must be taken in the interview
- 更改tabledata列名
- II Transforming regular expressions into finite state automata: NFA state machine recognizes input strings
- I Regular expression to finite state automata: regular expression to NFA
- Mysql database ignores case
- Dragon Boat Festival Ankang - - les Yankees dans mon cœur de plus en plus de zongzi
- 使用C语言代码实现工厂端LCD RGB的测试程序
- 网络层IP协议 ARP&ICMP&IGMP NAT
- Golandidea 2020.01 cracked version
猜你喜欢

DNA数字信息存储的研究进展

Tool classes for extracting zip files
软件测试报告中常见的疏漏,给自己提个醒
ADB command collection, let's learn together

测试用例如何编写?

Auto.js学习笔记7:js文件调用另一个js文件里的函数和变量,解决调用失败的各种问题
How should the test plan be written? A thought teaches you

MySQL-MVCC
Selenium面试题分享

Distributed transaction solution 1: TCC (compensation transaction)
随机推荐
使用Visual Studio 2017创建简单的窗口程序
L1-019 who goes first
Full arrangement of numbers (digital password dictionary)
Common technical questions in functional test interview. Would you like to summarize them?
Top command meaning
UEFI EDKII 编程学习
Counting haybales (difference + discretization)
(14) Inputfield logic analysis
Basic exercise letter graphics
JVM virtual machine
Is it necessary to separate databases and tables for MySQL single table data of 5million?
Auto.js学习笔记5:autojs的UI界面基础篇1
Common omissions in software test reports, give yourself a wake-up call
Basic knowledge of Linear Algebra -- concepts and relationships of common matrices
Autojs学习笔记6:text(txt).findOne()切换app时会报错,最后解决实现效果,切换任何app直到脚本找到指定的txt文字的控件进行点击。
Use of MYCAT
90%以上软件公司都会问的软件测试面试题赶紧来背吧
Oracle personal replication (I)
On absolute value function in C language
ADB command collection, let's learn together