当前位置:网站首页>The difference between abstract classes and interfaces
The difference between abstract classes and interfaces
2022-07-20 10:17:00 【Erdan~】
One 、 What is an abstract class ?
abstract class : stay java In language , use abstract class Keyword to define an abstract class , Define abstract side ( There is no method body ) Method must be in an abstract class , When subclasses inherit the abstract parent class, they must implement the abstract methods of the parent class ( Unless the subclass is also an abstract method ); Abstract classes can define “ quote ”, But it cannot be instantiated , But it can point to objects of any subclass
Two 、 What is the interface ?
Interface : use interface Keyword definition interface , Interfaces can define abstract methods ( Don't have to abstract modification ), Ordinary methods and construction methods cannot be defined , But you can define default methods (default modification ); An interface cannot define a member variable , Only constants can be defined ; Sure implement Multiple interfaces and allow “ multiple inheritance ”.
summary
adopt abstract The method of definition is abstract method , Only basic method definitions , There is no method body ;
When subclasses inherit the abstract parent class, they must implement the abstract methods of the parent class ( Unless the subclass is also an abstract method );
A class can only extends Inherit another class , But a class can implement Implement multiple interfaces ;
JDK 1.8 after , Allow definition of default Method ( The default method )
边栏推荐
猜你喜欢
Network Security Learning (XXII) build virtual special lines for companies and branches
2022-7-8 Group 8 Gu Yujia's Outward Bound Training
网安学习(二一)NAT 动态路由
DHCP原理与配置
Mikrotik ROS软路由设置上网方式(二)
7-1 懂的都懂
Mikrotik ROS软路由设置上网方式(一)
Software engineering final review mind map
Mikrotik ROS软路由设置上网方式(三)
2022-7-8 第八小组 顾宇佳 拓展训练
随机推荐
“==”与equals的区别
Leetcode:2. Add two numbers [large number addition + analog carry]
网安学习(二十四)传输层协议
Network Security Learning (21) NAT dynamic routing
Leetcode:13. Roman numeral to integer [key value pair mapping]
第三次实验 ospf
Nju Nanjing University elevation course: battlecity
Nanjing University calculation method (numerical analysis) final review notes
access-list vs ip access-list
Regular Expression
Leetcode:2. 两数相加【大数加法+模拟进位】
抽象类和接口的区别
Unity practical framework (I) scenario management framework
网络安全学习(二十三)防火墙
Leshan normal programming competition 2020-h: least common multiple [find the number of factors]
黑马程序员线程池
南京大学计算方法(数值分析)期末复习笔记
numpy中选择特定两行
Network Security Learning (XVIII) single arm routing, ICMP, layer 3 switching
2022-7-15 Gu Yujia's study notes of the eighth group