Java中final的使用规则

来源:互联网 发布:提高成绩的软件 编辑:程序博客网 时间:2024/05/18 03:17

问题见Stack Overflow。


Rule If you have initialized a final variable, then you cannot change it to refer to a different object. 

final classes cannot be subclassed
final methods cannot be overridden. (This method is in superclass)
final methods can override. (Read this in grammatical way. This method is in a subclass)


final 是指初始化了一个最终变量,那么您不能将其更改为引用另一个对象。

final classes 不能是子类
final methods 不能被覆盖. (该方法在父类)
final methods 可以被重写. (以语法方式阅读。 这个方法是一个子类)

原创粉丝点击