nerdexam
Oracle

1Z0-850 · Question #35

Given: 1. class Example { 2. int x = 50; 3. int y = 100; 4. public static void main(String args[]) { 5. int x = 0, y = 10; 6. Example ex = new Example(); 7. while (x < 3) { 8. x++; y--; 9. } 10…

The correct answer is B. x=3, y=7. See the full explanation below for the reasoning.

Question

Given:
  1. class Example {
  2. int x = 50;
  3. int y = 100;
  4. public static void main(String args[]) {
  5. int x = 0, y = 10;
  6. Example ex = new Example();
  7. while (x < 3) {
  8. x++; y--;
  9. }
  10. System.out.println("x = " + x + ", y = " + y);
  11. }
  12. } What is the result?

Options

  • ACompilation fails because of an error at line 8.
  • Bx=3, y=7
  • CCompilation fails because of an error at line 11.
  • DCompilation fails because of an error at line 9.
  • Ex=53, y=87
  • FCompilation fails because of an error at line 10.

How the community answered

(39 responses)
  • B
    72% (28)
  • C
    3% (1)
  • D
    8% (3)
  • E
    15% (6)
  • F
    3% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-850 Practice