可学答题网 > 问答 > SCJP程序员认证考试题库
目录: 标题| 题干| 答案| 搜索| 相关
问题

Which of the followi


Which of the following statements about variables and their scopes are true? ()   

  • A Instance variables are member variables of a class.
  • B Instance variables are declared with the static keyword.
  • C Local variables defined inside a method are created when the method is executed.
  • D Local variables must be initialized before they are used.
参考答案
参考解析:

类中有几种变量,分别是:局部变量(英文可以为:local\automatic\temporary\stack variable)是定义在方法里的变量;实例变量(英文为:instance variable)是在方法外而在类声明内定义的变量,有时也叫成员变量;类变量(英文为:class variable)是用关键字static声明的实例变量,他们的生存期分别是:局部变量在定义该变量的方法被调用时被创建,而在该方法退出后被撤销;实例变量在使用new Xxxx()创建该类的实例时被创建,而其生存期和该类的实例对象的生存期相同;类变量在该类被加载时被创建,不一定要用new Xxxx()创建,所有该类的实例对象共享该类变量,其生存期是类的生存期。任何变量在使用前都必须初始化,但是需要指出的是局部变量必须显式初始化,而实例变量不必,原始类型的实例变量在该类的构造方法被调用时为它分配的缺省的值,整型是0,布尔型是false,而浮点型是0.0f,引用类型(类类型)的实例变量的缺省值是null(没有进行实际的初始化,对它的使用将引起NullPointException),类变量的规则和实例变量一样,不同的是类变量的初始化是在类被加载时。

分类:SCJP程序员认证考试题库
相关推荐

1、Which of the followi

Which of the following is a true statement when promiscuous mode is enabled on an...

2、Which of the followi

Which of the following accurately represents the functionality of a lightweight access point&...

3、Which of the followi

Which of the following is not a CRS Telephony or Media Subsystem?()AJTAPI BCisco Media CVXML DMRCP ASR EMRCP TTS&e

4、Which of the followi

Which of the following characteristics applies only to OSPFv3 and not to OSPFv2?()ASeveral...

5、Which of the followi

Which of the following four CRS components must be active on a Historical Reporting&#81...

6、Which of the followi

Which of the following statements are true?() A The equals() method determines if refere...