Which of the following are correct?

a. A constructor must be declared for each class.
b. A constructor must be declared with a return type
c. A default constructor can only be provided by the compiler.
d. A class can have only one default constructor.
e. A class can have only one constructor.

d) is the only one that is correct.
Explanation: a) is wrong. The compiler will provide a default constructor if the class author does not. b) is wrong. In fact, a constructor may not have a return type. c) is wrong. In fact, as we will see later in this course, if the class author provides a constructor, the compiler will not provide a default constructor. If default constructor is needed under these circumstances, the class author must provide one.

Computer Science & Information Technology

You might also like to view...

An example of a natural key is sequential numbering from the AutoNumber data type

Indicate whether the statement is true or false

Computer Science & Information Technology

A worksheet of faculty members at your university contains these columns in this sequence: Rank, Last Name, First Name, Department, and Salary. What is the first step to subtotal departmental salaries?

A) Sort by Salary B) Sort by Department C) Sort by Last Name D) Sort by Rank

Computer Science & Information Technology