OCA Java SE 8 Building Blocks - OCA Mock Question Building Block 11
Question
Which of the following are true? (Choose all that apply)
- An instance variable of type boolean defaults to false.
- An instance variable of type boolean defaults to true.
- An instance variable of type boolean defaults to null.
- An instance variable of type int defaults to 0.
- An instance variable of type int defaults to 0.0.
- An instance variable of type int defaults to null.
- None of the above.
Answer
Note
A and D are correct because boolean primitives default to false and
int primitives default to 0.
String defaults to null.
double and float defaults to 0.0.
int, short, byte and long all default to 0.