exam questions

Exam 1z0-808 All Questions

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

Exam 1z0-808 topic 1 question 152 discussion

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

Given the code fragment:

What is the result?

  • A. 3
  • B. 0
  • C. Compilation fails.
  • D. -1
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

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
MPignaProTech
2 months, 3 weeks ago
Selected Answer: D
good answer is D
upvoted 1 times
...
DriftKing
1 year, 4 months ago
Selected Answer: D
Tested. Answer is D: -1 Code- public class Test{ public static void main(String[] args) { int wd = 0; String days[] = {"sun", "mon", "wed", "sat"}; for(String s:days) { switch (s) { case "sat": case "sun": wd -= 1; break; case "mon": wd -= 1; break; case "wed": wd += 2; } } System.out.println(wd); } }
upvoted 1 times
...
akbiyik
2 years, 1 month ago
Selected Answer: D
Answer is D.
upvoted 1 times
...
eilla
2 years, 1 month ago
Was confused on this one so an explanation in case anyone else is stuck! Because case "sat" doesn't have a break statement it then falls through the rest of the cases until it reaches a break. Therefore it hits the case "sun" statement, performs the subtraction of 1 and then breaks. So as it loops you get: Sun (wd=-1), Mon (wd=-2), Wed (wd=0), Sat (wd=-1)
upvoted 3 times
...
carloswork
2 years, 2 months ago
Selected Answer: D
Answer is D. To test: public static void main(String[] args) { int wd = 0; String days[] = {"sun", "mon", "wed", "sat"}; for(String s:days) { switch (s) { case "sat": case "sun": wd -= 1; break; case "mon": wd -= 1; break; case "wed": wd += 2; } } System.out.println(wd); }
upvoted 1 times
...
iSnover
2 years, 3 months ago
Selected Answer: C
The answer is the letter C, the compilation fails because the variable "wd" is an instance variable and is not local, instance variables to receive additions of values ​​inside a static method need to be static, as it is not, the code failure.
upvoted 1 times
UAK94
2 years, 3 months ago
Sorry but your comment is irrelevant. Answer is D.
upvoted 2 times
iSnover
2 years, 2 months ago
I liked your answer with arguments, thank you. :)
upvoted 1 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 ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago