当前位置:网站首页>【final关键字的使用】
【final关键字的使用】
2022-07-26 08:52:00 【伏月初五】
概念:关键字final表示最终的,不可变的。
- 关键字final可以修饰变量、方法,类
- final修饰的类无法被继承
- 当不希望父类的方法被子类覆盖或者重写可以使用final
- 当不希望属性被修改时可以使用final
- 当不希望某个局部变量被修改时可以使用final
- final修饰的变量只能赋一次值
使用细节:
- final修饰的属性又叫常量
- final修饰的属性必须在定义时赋值,并且以后无法修改,赋值位置可在(定义时赋值、构造器赋值、代码块赋值),如果final修饰的属性是静态的,只能使用定义时或者静态代码块赋值,不可使用构造器
- final类不能被继承,但是可以实例化对象
- 如果类不是final类,但是有final方法,该方法虽然不能重写,但是可以被继承
- 一般来说,如果一个类是final类,就没必要修饰成 final 方法了
- final方法不能修饰构造方法,即构造器
- 包装类(Integer,double,float,Boolean,String都是final类),不可改变的
边栏推荐
- SSH,NFS,FTP
- Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
- Web overview and b/s architecture
- P3743 kotori的设备
- Hegong sky team vision training Day6 - traditional vision, image processing
- day06 作业--增删改查
- Form form
- Oracle 19C OCP 1z0-082 certification examination question bank (30-35)
- [freeswitch development practice] use SIP client Yate to connect freeswitch for VoIP calls
- Database operation skills 6
猜你喜欢
Transfer guide printing system based on C language design
Cadence(十)走线技巧与注意事项
OA项目之我的会议(会议排座&送审)
C Entry series (31) -- operator overloading
[database] gbase 8A MPP cluster v95 installation and uninstall
[freeswitch development practice] use SIP client Yate to connect freeswitch for VoIP calls
Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
CSDN TOP1“一个处女座的程序猿“如何通过写作成为百万粉丝博主?
Study notes of automatic control principle --- stability analysis of control system
Learning notes of automatic control principle --- linear discrete system
随机推荐
Foundry tutorial: writing scalable smart contracts in various ways (Part 1)
Nuxt - 项目打包部署及上线到服务器流程(SSR 服务端渲染)
The largest number of statistical absolute values --- assembly language
TypeScript版Snowflake主键生成器
Day06 homework - skill question 6
【搜索专题】看完必会的搜索问题之洪水覆盖
[search topics] flood coverage of search questions after reading the inevitable meeting
Registration of finite element learning knowledge points
Probability model in machine learning
day06 作业--技能题2
The lessons of 2000. Web3 = the third industrial revolution?
OA项目之我的会议(查询)
Web概述和B/S架构
at、crontab
CSDN Top1 "how does a Virgo procedural ape" become a blogger with millions of fans through writing?
Cve-2021-26295 Apache OFBiz deserialization Remote Code Execution Vulnerability recurrence
[freeswitch development practice] user defined module creation and use
Oracle 19C OCP 1z0-082 certification examination question bank (7-12)
[suggestions collection] summary of MySQL 30000 word essence - locking mechanism and performance tuning (IV) [suggestions collection]
Ansible important components (playbook)