Exam 1z0-829 All QuestionsBrowse all questions from this exam
Question 23

Given:

What is the result?

    Correct Answer: C

    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
TojoseOption: C

the right answer is C. 1001 100 1000

james2033Option: C

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

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