多选题
What is the correct way to initialize a variable declared with the data type of Book , as a new Book object?
A. Book b;
B. Book b = new Book();
C. Book b = new Book[];
D. Book b = Book();
A
B
C
D
【正确答案】
B
【答案解析】
声明一个对象的正确方法是使用new,然后对象名后面跟着圆括号。如果需要的话,圆括号用来向构造函数传递参数。A、C和D不正确。A不正确,因为它没有初始化一个新的Book对象。C不正确,因为使用了方括号而不是圆括号。D不正确,因为缺少new关键字。
提交答案
关闭