当前位置:网站首页>【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类),不可改变的
边栏推荐
- 合工大苍穹战队视觉组培训Day5——机器学习,图像识别项目
- TCP solves the problem of short write
- node的js文件引入
- Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
- Oracle 19C OCP 1z0-082 certification examination question bank (36-41)
- The idea shortcut key ALT realizes the whole column operation
- Day06 homework - skill question 7
- Pan micro e-cology8 foreground SQL injection POC
- Sklearn machine learning foundation (linear regression, under fitting, over fitting, ridge regression, model loading and saving)
- Kotlin properties and fields
猜你喜欢

《Datawhale熊猫书》出版了!

Arbitrum Nova release! Create a low-cost and high-speed dedicated chain in the game social field

Database operation topic 1

Datawhale panda book has been published!
![[freeswitch development practice] user defined module creation and use](/img/5f/3034577e3e2bc018d0f272359af502.png)
[freeswitch development practice] user defined module creation and use

day06 作业---技能题7

数据库操作技能7

keepalived双机热备
![[eslint] Failed to load parser ‘@typescript-eslint/parser‘ declared in ‘package. json » eslint-confi](/img/39/135d29dae23b55497728233f31aa6a.png)
[eslint] Failed to load parser ‘@typescript-eslint/parser‘ declared in ‘package. json » eslint-confi

【加密周报】加密市场有所回温?寒冬仍未解冻 盘点上周加密市场发生的重大事件
随机推荐
Foundry教程:使用多种方式编写可升级的智能合约(上)
Cadence(十)走线技巧与注意事项
Transfer guide printing system based on C language design
Registration of finite element learning knowledge points
[database] gbase 8A MPP cluster v95 installation and uninstall
Store a group of positive and negative numbers respectively, and count the number of 0 -- assembly language implementation
Learning notes of automatic control principle - Performance Analysis of continuous time system
Web3 Games: current situation and future
Review notes of Microcomputer Principles -- zoufengxing
Recurrence of SQL injection vulnerability in the foreground of a 60 terminal security management system
Uploading pictures on Alibaba cloud OSS
Probability model in machine learning
CIS 2020 - alternative skills against cloud WAF (pyn3rd)
Oracle 19C OCP 1z0-082 certification examination question bank (19-23)
TypeScript版加密工具PasswordEncoder
2000年的教训。web3是否=第三次工业革命?
Ansible important components (playbook)
[recommended collection] MySQL 30000 word essence summary index (II) [easy to understand]
OA项目之我的会议(查询)
Rocky基础练习题-shell脚本2