当前位置:网站首页>抽象类和接口的区别
抽象类和接口的区别
2022-08-08 06:27:00 【小田同学卷代码】
1.抽象类:
(1)在抽象类中既可以声明普通的方法,也可以声明抽象的方法,抽象的方法必须使用abstract关键字修饰,子类继承后需重写抽象方法。
(2)在抽象类中可以声明构造器,且有默认的空参构造器。目的:在创建子类对象前先初始化其父类。
(3)在抽象类中既可以声明属性,也可以声明常量。
(4)一个类只能继承于一个父类(单继承性)。(extends)
(5)类之间不能实现多重继承。
2.接口:
(1)在接口中只能声明抽象的方法,且方法可以不用abstract关键字修饰。实现类在实现接口时需要重写该接口的所有抽象方法。
(2)接口中不能声明构造器。
(3)在接口中只能声明常量,且需要显示初始化,接口中的常量不能被调用修改。
(4)一个类可以实现多个接口。(implements)
(5)接口之间可以实现多重继承。
边栏推荐
- 什么是类与对象?
- Background Suppression Network for Weakly-supervised Temporal Action Localization
- 【图形学】11 UnityShader入门(三)
- 网络安全笔记第二天day2(等级保护)
- [Unity] GPU动画实现(三)——材质合并
- 【图形学】12 UnityShader语法入门
- 【爬虫】Web Scraper正则表达式
- Solved the problem that when VRTK transmission under Unity HDRP, the screen fades in and out, and the visual occlusion cannot be displayed correctly when passing through the wall
- 使用websocket实现服务端主动发送消息到客户端
- 【Android安全】Binder解析
猜你喜欢
计算机网络 | 03.[HTTP篇] HTTP缓存技术
Solved the problem that when VRTK transmission under Unity HDRP, the screen fades in and out, and the visual occlusion cannot be displayed correctly when passing through the wall
【服务器运维】忘记XShell 服务器口令
【图形学】01 数学部分(一、集合和三角函数)
acwing 63rd weekly match【2022.08.06】
C language judges the problem of big and small endian storage
Unity—ParticleSystem (particle system) and Animator (animation state machine) batch manager
实现字符串转换为整数(atoi)
【图形学】18 光照模型(三、镜面反射的Shader实现)
tcpdump进行ARP抓包
随机推荐
Unity_常用数据分析总结:折线图、条形图(柱状图)、扇形图(饼状图)、雷达图(属性图)
【图形学】13 UnityShader语义(一)
字符串匹配问题小结
Unity_组件自动绑定
【数据序列化】扁平结构与嵌套结构
Nine common interfaces for implementing sequence table in C language
NVIDIA CUDA Highly Parallel Processor Programming (6): Parallel Mode: Convolution
排列组合题目小结
UGUI_编辑器扩展与常用优化
Chained queue push and pop related operations
实现字符串转换为整数(atoi)
leetcode daily question 8.6 (continuously updated)
在字符串中查找子字符串
Mysql大并发热点行更新的两个骚操作
tcpdump进行ARP抓包
编程更改镜像总结
【Unity】unity中对象池的使用
【Excel】csv文件修改分隔符
三元表达式,各种生成式,匿名函数相关知识点
Unity_对象池