What is the main purpose of a constructor?
Explanation
A constructor runs once, at the moment an object comes into existence, and its job is to leave that object ready to use. Everything else about constructors follows from this purpose.
- A is not correct: establishing the object's state is precisely what a constructor is for.
- C is not correct: the visibility of an instance variable is set by its own declaration, and the usual choice is
private. - D is not correct: a constructor has no return type and returns nothing explicitly.