1Z0-803 · Question #243
Given: public class FieldInit { char c; boolean b; float f; void printAll() { System.out.println("c = " + c); System.out.println("c = " + b); System.out.println("c = " + f); } public static void main(
The correct answer is D. c =. This question evaluates understanding of default initialization values for primitive fields in Java and the display behavior of the null character when printed.
Question
Options
- Ac = null
- Bc = 0
- Cc = null
- Dc =
How the community answered
(26 responses)- B8% (2)
- C4% (1)
- D88% (23)
Why each option
This question evaluates understanding of default initialization values for primitive fields in Java and the display behavior of the null character when printed.
`null` is the default value for reference types, not primitive types like `char`, `boolean`, or `float`.
While the ASCII value of `\u0000` is 0, `System.out.println` prints its character representation, which is invisible, not the digit `0`.
Similar to choice A, `null` is the default for reference types, not primitive types.
The `char` field `c` is an instance variable and is automatically initialized to its default value of the null character `\u0000`. When `System.out.println` prints `\u0000`, it produces no visible output, resulting in the line "c = " followed by a newline.
Concept tested: Java primitive data type default values, char printing
Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
Topics
Community Discussion
No community discussion yet for this question.