exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 33 discussion

Actual exam question from Oracle's 1z0-808
Question #: 33
Topic #: 1
[All 1z0-808 Questions]

Given:

And:

What is the result?

  • A. Option A
  • B. Option B
  • C. Option C
  • D. Option D
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
vic88
8 months ago
Selected Answer: A
A is right
upvoted 1 times
...
DarGrin
1 year, 9 months ago
A is correct
upvoted 1 times
...
chuducanhchy
2 years, 5 months ago
Selected Answer: A
Answer is A, default value of primitive int is 0.
upvoted 1 times
...
carloswork
2 years, 9 months ago
Selected Answer: A
Answer is A. To test: class Alpha { int ns; static int s; Alpha(int ns){ // constructor if(s < ns) { s = ns; this.ns = ns; } } void doPrint() { System.out.println("ns = " + ns + " s = " + s); } } public class Test { public static void main(String[] args) { Alpha ref1 = new Alpha(100); Alpha ref2 = new Alpha(50); Alpha ref3 = new Alpha(125); ref1.doPrint(); ref2.doPrint(); ref3.doPrint(); } }
upvoted 1 times
...
EmiTanase
2 years, 10 months ago
Why s is 125 than ns is 0?
upvoted 1 times
RoxyFoxy
2 years, 10 months ago
Hi, Emi! So, first we have: instance variable ns = 0 and static variable s = 0 When we call the constructor, we will have: Alpha (100): if (s < ns) then s = ns and this.ns = ns so: if (0 <100) then s = 100 and this.ns = 100 Alpha(50): now s = 100 because is static (updated above) if (100 < 50) which is false. ns = 0 because the instance variable is 0. Alpha(125): At this point, s = 100 if (100 < 125) then s = 125 and ns = 125. So here s is updated! At this point, when we call System.out.println(), for all ref1, ref2, ref3 the value of s is 125 (remember s is static). For ref1, ns = 100, for ref2 ns = 0, and for ref3 ns = 125. I hope this helps you :) Roxy
upvoted 9 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...