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:
- class Example {
- int x = 50;
- int y = 100;
- public static void main(String args[]) {
- int x = 0, y = 10;
- Example ex = new Example();
- while (x < 3) {
- x++; y--;
- }
- System.out.println("x = " + x + ", y = " + y);
- }
- } 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)- B72% (28)
- C3% (1)
- D8% (3)
- E15% (6)
- F3% (1)
Community Discussion
No community discussion yet for this question.