Microsoft
98-361 · Question #358
Suppose that you are writing code for a class named Product. You need to make sure that the data members of the class are initialized to their correct values as soon as you create an object of the…
The correct answer is B. Create a constructor in the Product class to initialize data members. See the full explanation below for the reasoning.
Question
Suppose that you are writing code for a class named Product. You need to make sure that the data members of the class are initialized to their correct values as soon as you create an object of the Product class. The initialization code should always be executed. What should you do?
Options
- ACreate a static method in the Product class to initialize data members.
- BCreate a constructor in the Product class to initialize data members.
- CCreate a static property in the Product class to initialize data members.
- DCreate an event in the Product class to initialize data members.
How the community answered
(18 responses)- A6% (1)
- B78% (14)
- C11% (2)
- D6% (1)
Community Discussion
No community discussion yet for this question.