当前位置:网站首页>【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类),不可改变的
边栏推荐
- Form form
- day06 作业---技能题7
- Pxe原理和概念
- sklearn 机器学习基础(线性回归、欠拟合、过拟合、岭回归、模型加载保存)
- What are the differences in the performance of different usages such as count (*), count (primary key ID), count (field) and count (1)? That's more efficient
- TypeScript版加密工具PasswordEncoder
- Mutual transformation of array structure and tree structure
- Day 6 summary & database operation
- Implementation of Prometheus web authentication and alarm
- 03异常处理,状态保持,请求钩子---04大型项目结构与蓝图
猜你喜欢

My meeting of OA project (meeting seating & submission for approval)

OA项目之我的会议(会议排座&送审)

JS file import of node

解决C#跨线程调用窗体控件的问题

Database operation topic 1

Review notes of Microcomputer Principles -- zoufengxing

Learning notes of automatic control principle - Performance Analysis of continuous time system

Numpy Foundation

Day06 homework -- skill question 1

ES6模块化导入导出)(实现页面嵌套)
随机推荐
uni-app 简易商城制作
Implementation of Prometheus web authentication and alarm
[search topics] flood coverage of search questions after reading the inevitable meeting
The lessons of 2000. Web3 = the third industrial revolution?
Regular expression: judge whether it conforms to USD format
JDBC数据库连接池(Druid技术)
P3743 Kotori's equipment
Day06 homework -- skill question 1
sklearn 机器学习基础(线性回归、欠拟合、过拟合、岭回归、模型加载保存)
[untitled]
Arbitrum Nova release! Create a low-cost and high-speed dedicated chain in the game social field
Learning notes of automatic control principle - Performance Analysis of continuous time system
The effective condition of MySQL joint index and the invalid condition of index
Mutual transformation of array structure and tree structure
Study notes of automatic control principle -- dynamic model of feedback control system
Oracle 19C OCP 1z0-082 certification examination question bank (42-50)
网络安全漫山遍野的高大上名词之后的攻防策略本质
数据库操作 题目二
Poor English, Oracle OCP or MySQL OCP exam can also get a high score of 80 points
合工大苍穹战队视觉组培训Day6——传统视觉,图像处理