nerdexam
Oracle

1Z0-803 · Question #203

Given: What is the result?

The correct answer is B. x:0 y:0. The code likely declares instance variables x and y without explicit initialization, causing them to be assigned their default value of zero for primitive integer types.

Using Operators and Decision Constructs

Question

Given:

What is the result?

Exhibit

1Z0-803 question #203 exhibit

Options

  • Ax:1 y:2
  • Bx:0 y:0
  • Cx:3 y:4
  • Dx:3 y:4

How the community answered

(33 responses)
  • A
    12% (4)
  • B
    79% (26)
  • C
    6% (2)
  • D
    3% (1)

Why each option

The code likely declares instance variables `x` and `y` without explicit initialization, causing them to be assigned their default value of zero for primitive integer types.

Ax:1 y:2

The values 1 and 2 for `x` and `y` would only be present if they were explicitly assigned those values, which contradicts the behavior of default initialization for uninitialized instance variables.

Bx:0 y:0Correct

In Java, if instance variables of primitive numeric types like `int` (for `x` and `y`) are declared within a class but not explicitly initialized by the programmer in their declaration or a constructor, they are automatically assigned their default value, which is 0 for `int`.

Cx:3 y:4

The values 3 and 4 for `x` and `y` would only be present if they were explicitly assigned those values, which contradicts the behavior of default initialization for uninitialized instance variables.

Dx:3 y:4

This choice is a duplicate of C, indicating explicit initialization rather than the default values for uninitialized instance variables.

Concept tested: Default initialization of instance variables in Java

Source: https://docs.oracle.com/javase/tutorial/java/javaOO/variables.html

Topics

#increment operators#variable state#operator precedence

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice