当前位置:网站首页>Final关键字
Final关键字
2022-04-22 06:15:00 【尽欢Sir】
Final关键字的用法
final修饰变量
1、final修饰的变量都是常量
2、final修饰的变量'无法对其重新赋值'
第一种用法:先声明变量、后赋值、一旦赋值,不可改变(无法二次赋值)
final int NUM;
NUM = 10;//可以赋值成功
NUM = 20;//报错,因为不能二次赋值
第二种赋值方法:直接在声明变量的时候赋值
final int AGE = 18;
AGE = 20;//报错
注意:
final修饰的变量为局部变量的时候,以上两种方法都可以使用
但是'当final修饰的是成员变量的时候,必须在声明时赋值'
final修饰类
final 修饰的类表示为“最终类”,'无法被继承'
final修饰方法
final 修饰的方法'无法被重写',即无法被子类覆盖
版权声明
本文为[尽欢Sir]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_51724241/article/details/123459194
边栏推荐
- 面试官常问的,对象分配的一般过程及特殊情况
- Leetcode - 6 - (chaîne multiplicatrice, prochain élément plus grand < Ⅰ Ⅱ Ⅲ >, K liste de chaînes inversées)
- [number theory] prime number (V): Mason prime number (lucas_lehmer decision method)
- 762 · 最长公共子序列 II
- idea 不显示Run Dashboard视图窗口的问题
- Add author photos and author profiles to latex
- synchronized锁优化的一些机制(锁升级)
- instanceof的使用说明及实例讲解
- L2-001 紧急救援 (最短路Dijkstra的扩展 - 最短路径数&路径最大权值)
- 【数论】素数(五):梅森素数(Lucas_Lehmer判定法)
猜你喜欢

Write a method Sanjiao (a, B, c) to judge whether the three parameters can form a triangle. If not, throw an exception illegalargumentexception and display the exception information a, B, C "cannot fo

Cannot find interface mapping after updating HDF

链表难题记录一

面试官常问的,对象分配的一般过程及特殊情况

内部类使用说明(静态、实例、局部)

Redis进阶

(五) 使用Navicat创建数据库数据表并设置id自增

L2-001 紧急救援 (最短路Dijkstra的扩展 - 最短路径数&路径最大权值)

What is the internal structure of stack frame?

278 · 绘制填充
随机推荐
Some mechanisms of synchronized lock optimization (lock upgrade)
友情链接汇总qwq
【数论】同余(二):逆元
L2-001 紧急救援 (最短路Dijkstra的扩展 - 最短路径数&路径最大权值)
Codeforces Round #778
[number theory] prime number (2): prime number sieve method (Egyptian sieve, Euler sieve, interval sieve)
链表习题详解
[number theory] congruence (7): fast power, fast power of matrix
Win10 Anaconda install cocotb
Win10 modify command line default font
手撕算法---LRU缓存淘汰策略,问的这么频繁
296 · 数组去重
最强数组学习之路
浅谈时间复杂度与空间复杂度
15 · 全排列
LeetCode - 4 - (接雨水、无重复字符的最长子串、分发糖果、二叉树的<前中后层>序遍历)
[number theory] Euler function (basic properties, recursive method, formula method, linear sieve method)
快排与归并排序
Add author photos and author profiles to latex
内部类使用说明(静态、实例、局部)