多选题 Given the SampleClass, when the following code segment is executed, what is the value of the instance variable size?
SampleClass sampleClass = new SampleClass(5);
public class SampleClass {
private int size;
public SampleClass(int size) {
size = size;
}
}
  • A. 0
  • B. 1
  • C. 5
  • D. Compiler error
  • E. Runtime error
【正确答案】 A
【答案解析】实例变量被参数隐藏,因为它们都具有相同的名字。要设置size为5,必须使用this.size=size。该实例变量为0,因为这是赋予实例变量的默认值。B、C、D和E不正确。B不正确,因为默认情况下,实例变量设置为0,而不是1。D和E不正确,因为该代码是有效的。