1Z0-803 · Question #172
Given: What is the result?
The correct answer is B. ns = 50 S = 125. The output indicates ns is an instance-specific value of 50, while S is likely a static variable that has been updated to 125 through a class-level operation.
Question
Given:
What is the result?
Exhibit
Options
- Ans = 50 S = 125
- Bns = 50 S = 125
- Cns = 50 S = 50
- Dns = 50 S = 50
How the community answered
(21 responses)- A10% (2)
- B71% (15)
- C14% (3)
- D5% (1)
Why each option
The output indicates `ns` is an instance-specific value of 50, while `S` is likely a static variable that has been updated to 125 through a class-level operation.
This option is identical in content to the correct answer B, but B is specified as the correct choice.
The result `ns = 50 S = 125` implies that `ns` (likely an instance variable) maintains its initial or set value of 50, while `S` (likely a static class variable) is modified to a distinct value of 125, possibly through operations affecting the class as a whole or cumulative calculations across instances.
If both `ns` and `S` had values of 50, it would typically mean both are instance variables or `S` was also explicitly set to 50, which contradicts the distinct value of 125 for `S` in the correct answer.
Similar to C, this result would suggest `S` also ends up at 50, which doesn't align with the likely scenario of `S` being a static variable modified to a distinct value.
Concept tested: Java instance vs. static variable scope
Source: https://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html
Topics
Community Discussion
No community discussion yet for this question.
