当前位置:网站首页>【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类),不可改变的
边栏推荐
- Pop up window in Win 11 opens with a new tab ---firefox
- Replication of SQL injection vulnerability in the foreground of Pan micro e-cology8
- PXE principles and concepts
- CSDN TOP1“一个处女座的程序猿“如何通过写作成为百万粉丝博主?
- Dynamic SQL and exceptions of pl/sql
- [recommended collection] MySQL 30000 word essence summary - query and transaction (III)
- Arbitrum launched the anytrust chain to meet the diverse needs of ecological projects
- TypeScript版Snowflake主键生成器
- day06 作业--技能题6
- Database operation topic 1
猜你喜欢

Huffman transformation software based on C language

Sklearn machine learning foundation (linear regression, under fitting, over fitting, ridge regression, model loading and saving)

My meeting of OA project (query)

Cadence (x) wiring skills and precautions

03异常处理,状态保持,请求钩子---04大型项目结构与蓝图

数据库操作 技能6

合工大苍穹战队视觉组培训Day6——传统视觉,图像处理

Vision Group Training Day5 - machine learning, image recognition project

TCP solves the problem of short write

合工大苍穹战队视觉组培训Day5——机器学习,图像识别项目
随机推荐
Web overview and b/s architecture
at、crontab
After MySQL 8 OCP (1z0-908), hand in your homework
CIS 2020 - alternative skills against cloud WAF (pyn3rd)
【搜索专题】看完必会的搜索问题之洪水覆盖
Cadence(十)走线技巧与注意事项
Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
Study notes of automatic control principle -- correction and synthesis of automatic control system
Introduction to AWD attack and defense competition
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
Oracle 19C OCP 1z0-082 certification examination question bank (30-35)
Solve the problem of C # calling form controls across threads
Review notes of Microcomputer Principles -- zoufengxing
keepalived双机热备
(1) CTS tradefed test framework environment construction
Day06 homework - skill question 6
Oracle 19C OCP 1z0-082 certification examination question bank (7-12)
Oracle 19C OCP 1z0-082 certification examination question bank (36-41)
Arbitrum launched the anytrust chain to meet the diverse needs of ecological projects
[encryption weekly] has the encryption market recovered? The cold winter still hasn't thawed out. Take stock of the major events that occurred in the encryption market last week