问题:
Given the following code fragment:
public void create() {
Vector myVect;
myVect = new Vector();
}
Which of the following statements are true?()
A . The declaration on line 2 does not allocate memory space for the variable myVect.
B . The declaration on line 2 allocates memory space for a reference to a Vector object.
C . The statement on line 2 creates an object of class Vector.
D . The statement on line 3 creates an object of class Vector.
E . The statement on line 3 allocates memory space for an object of class Vector.
Given the following code fragment:
public void create() {
Vector myVect;
myVect = new Vector();
}
Which of the following statements are true?()
● 参考解析
SL-275中指出:要为一个新对象分配空间必须执行new Xxx()调用,new调用执行以下的操作:
1.为新对象分配空间并将其成员初始化为0或者null。
2.执行类体中的初始化。(例如在类中有一个成员声明int a=10;在第一步后a=0 ,执行到第二步后a=10)
3.执行构造函数。
4.变量被分配为一个到内存堆中的新对象的引用。