【问题标题】:What is the difference between final, const and static variables in javajava中的final,const和static变量有什么区别
【发布时间】:2015-05-11 08:40:48
【问题描述】:

java中的final、const和static变量有什么区别 请用代码示例 `

【问题讨论】:

  • 这个很基础,你可以在网上到处找。
  • @mr.icetea 是的,我确实在谷歌上搜索过它们,但是在收集所有信息时我感到很困惑,所以我要求提供一个代码示例,以使其尽可能清晰..

标签: java variables static constants final


【解决方案1】:
class X
{
  static int s; // can be accessed as X.s without object
  final int f = 7; // can't be assigned a different value
  const int c; // doesn't compile
}

【讨论】:

  • 谢谢@Atsby 我明白了:)
猜你喜欢
  • 2013-10-28
  • 2012-06-28
  • 2012-12-26
  • 2011-04-09
  • 1970-01-01
  • 2020-01-24
  • 1970-01-01
  • 2019-02-20
相关资源
最近更新 更多