“最终"关键字示例? [英] 'final' keyword example?
本文介绍了“最终"关键字示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以举一个"final"关键字的例子吗?
Can someone give an example of ''final'' keyword?
推荐答案
在类上,它可以防止子类化
在字段上,它可防止实例化而无需初始化字段
在局部变量上,它声明为常量
on a class, it prevents sub classing
on a field, it prevents instantiation without initializing the field
on a local variable, it declares it to be constant
class clsfinal
{
public static void main(String[] arrValues)
{
final int PI = 3.14;
}
}
所以在这里您不能修改变量PI的值.
so here you can''t modify the value of the variable PI.
这篇关于“最终"关键字示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文