In addtion to the uses of final to prevent overridden or Inheritance, final can also be applied to variables to create what amounts to named constants. If you precede a class variable's name with final, its value cannot be changed. below shows how to define a named constants in java and its same form in C++:
JAVA: final int ERRCODE = 10;
C++: const int ERRCODE = 10;
JAVA: final int ERRCODE = 10;
C++: const int ERRCODE = 10;
本文介绍了如何使用final关键字在Java和C++中定义常量。通过将final应用于变量,可以创建不可更改的命名常量。示例展示了在两种语言中定义ERRCODE常量的方法。
9296

被折叠的 条评论
为什么被折叠?



