0

Any constructor must explicitly initialize all fields of a class. (Java)

Is this statement true or false? And Can someone please explain why? I do not understand the question.

Buddy
  • 47
  • 1

2 Answers2

1

This statement is false, because all the fields of a class are initialized to their default type values. A reference on an object is initialized to null, an int to 0, a double to 0.0 etc...

Mohammed Aouf Zouag
  • 17,042
  • 4
  • 41
  • 67
1

First of, please try it.

To answer the question: No. A constructor does not have to initialize all fields.

After the construction of an object all final fields must be initialized.

All non-final variables have default variables in Java. Reference

Emz
  • 1,280
  • 1
  • 14
  • 29