1z0-829 Exam QuestionsBrowse all questions from this exam

1z0-829 Exam - Question 23


Given:

What is the result?

Show Answer
Correct Answer: BC

The code first declares a public instance variable x with the value 100. In the main method, it declares a local variable x with the value 1000. It creates an instance of the App class and calls the myMethod using the local variable x. Inside myMethod, the x parameter is incremented by 1, making it 1001. The first println inside myMethod prints this incremented value 1001. The second println uses this.x which refers to the instance variable, so it prints 100. Finally, the main method prints the local variable x, which remains 1000 as it is not modified. Therefore, the result is 1001, 100, 1000.

Discussion

3 comments
Sign in to comment
TojoseOption: C
Jan 11, 2024

the right answer is C. 1001 100 1000

james2033Option: C
Feb 22, 2024

package q23; public class App { public int x = 100; public static void main(String[] args) { int x = 1000; App t = new App(); t.myMethod(x); System.out.println(x); } public void myMethod(int x) { x++; System.out.println(x); System.out.println(this.x); } } // Result: // 1001 // 100 // 1000

xplorerpjOption: C
Jun 19, 2024

Right answer is C this.x refers to publicly declared/initialized variable