当前位置: 技术问答>java相关
SCJP模拟题 about Default Constructor
来源: 互联网 发布时间:2015-03-30
本文导语: 125. Which two statements are true regarding the creation of a default constructor? (Choose Two) A. The default constructor initializes method variables. B. The default constructor invokes the no-parameter constructor of the superclass. C. The def...
125. Which two statements are true regarding the creation of a default constructor? (Choose Two)
A. The default constructor initializes method variables.
B. The default constructor invokes the no-parameter constructor of the superclass.
C. The default constructor initializes the instance variables declared in the class.
D. If a class lacks a no-parameter constructor, but has other constructors, the compiler creates a default constructor.
E. The compiler creates a default constructor only when there are no other constructors for the class.
我选择B。E.
答案确是C.E.
我认为答案错了,不敢确定,来请教一下大家
A. The default constructor initializes method variables.
B. The default constructor invokes the no-parameter constructor of the superclass.
C. The default constructor initializes the instance variables declared in the class.
D. If a class lacks a no-parameter constructor, but has other constructors, the compiler creates a default constructor.
E. The compiler creates a default constructor only when there are no other constructors for the class.
我选择B。E.
答案确是C.E.
我认为答案错了,不敢确定,来请教一下大家
|
还记得构造方法的构造顺序吗?
class X
{
Object o=new Object();//这个?
}
编译后实际是:
class X
{
Object o;
public X() {
o=new Object()
}
}
它的初始化就是指这个。
class X
{
Object o=new Object();//这个?
}
编译后实际是:
class X
{
Object o;
public X() {
o=new Object()
}
}
它的初始化就是指这个。
|
正确答案是C、E!!!
cherami(cherami)解释的很详细。有一点,我纠正一下
即自己定义的无参的构造方法也可以称为default constructor 的话
————————这个不能称之为default constructor !!!default constructor 是JVM在编译时由系统自动提供的!!!
cherami(cherami)解释的很详细。有一点,我纠正一下
即自己定义的无参的构造方法也可以称为default constructor 的话
————————这个不能称之为default constructor !!!default constructor 是JVM在编译时由系统自动提供的!!!