Java OCA OCP Practice Question 1630

Question

Which statements are true?.

Select the two correct answers.

  • (a) A class must define a constructor.
  • (b) A constructor can be declared private.
  • (c) A constructor can return a value.
  • (d) A constructor must initialize all fields when a class is instantiated.
  • (e) A constructor can access the non-static members of a class.


(b) and (e)

Note

A constructor can be declared private, but this means that this constructor can only be used within the class.

Constructors need not initialize all the fields when a class is instantiated.

A field will be assigned a default value if not explicitly initialized.

A constructor is non-static and, as such, it can directly access both the static and non-static members of the class.




PreviousNext

Related