nerdexam
Oracle

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.

Working with Java Data Types

Question

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(String[] args) { FieldInit f = new FieldInit(); f.printAll(); } } What is the result?

Options

  • Ac = null
  • Bc = 0
  • Cc = null
  • Dc =

How the community answered

(26 responses)
  • B
    8% (2)
  • C
    4% (1)
  • D
    88% (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.

Ac = null

`null` is the default value for reference types, not primitive types like `char`, `boolean`, or `float`.

Bc = 0

While the ASCII value of `\u0000` is 0, `System.out.println` prints its character representation, which is invisible, not the digit `0`.

Cc = null

Similar to choice A, `null` is the default for reference types, not primitive types.

Dc =Correct

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

#default values#primitive data types#instance variables#member initialization

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice