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.
Question
Given:
What is the result?
Exhibit
Options
- Ax:1 y:2
- Bx:0 y:0
- Cx:3 y:4
- Dx:3 y:4
How the community answered
(33 responses)- A12% (4)
- B79% (26)
- C6% (2)
- D3% (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.
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.
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`.
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.
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
Community Discussion
No community discussion yet for this question.
