Java变量名称和保留字

huangapple go评论114阅读模式
英文:

Java variables name and reserved words

问题

"lenght" 是 Java 中的一个预定义变量。但是 Java 用户可以在我们自己的类中使用 "lenght" 作为变量名。

示例:
int length = 10;

  1. 为什么 length 不是 Java 中的保留字?
  2. 在类中使用 length 作为变量名是否可以?
英文:

"lenght" is a predefined variable in java. But Java users can use "lenght" is a variable name in our own classes.

Example:
int length = 10;

  1. Why length is not a reserved word in java?
  2. Is it ok to use length as a variable name in a class?.

答案1

得分: 1

Length是数组的实例变量,只要您不在某个数组的上下文中使用它,它就不是保留字。字符串类有一个名为length的实例方法,但同样不是保留字。

英文:

Length is an instance variable for arrays, so as long as you don't use in the context of someArray.length, it is not reserved. The string class has an instance method called length, but again, not reserved.

huangapple
  • 本文由 发表于 2020年7月22日 08:57:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/63025185.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定