exam questions

Exam 1z0-808 All Questions

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

Exam 1z0-808 topic 1 question 195 discussion

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

Given the code fragment:

What is the result?

  • A. The sum of 4 numbers is: 10
  • B. A compile time error occurs.
  • C. The sum of 5 numbers is: 10
  • D. The sum of 5 numbers is: 15
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

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
Bear4TW
2 months, 1 week ago
Selected Answer: B
To test: public static void main(String[] args) { int sum = 0; for (int xVal = 1; xVal <= 5; xVal++) { sum = sum + xVal; } System.out.println("The sum of " + xVal + " numbers is: " + sum); }
upvoted 1 times
...
dsms
4 months, 3 weeks ago
Selected Answer: B
answer is B: "A compile time error occurs." xVal - is unreachable outside FOR loop
upvoted 1 times
...
iSnover
1 year, 3 months ago
Selected Answer: B
The correct answer is the letter B, it is the typical case of differentiating between local variable and instance variable, as the local variable "xVal" was instantiated inside the for, the code inside the for compiles normally, but when exiting for and trying printing the variable inside the class cannot because there is no variable created with that name, as "xValr" is a local variable, its instantiation is only valid locally inside the for and not outside it.
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