Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 81

Given:

What is the result?

    Correct Answer: A

    The method doStuff assigns the parameters x and y to the local variables x and this.y respectively. However, in Java, the statement x = x; assigns the parameter x to itself, which does not impact the instance variable x. Similarly, y = this.y; assigns the current value of the instance variable y to itself, so no actual change happens. Therefore, the variables x and y for the instance m2 are not modified and retain their default values of 0, leading to the output being 100 200 : 0 0 :.

Discussion
iSnoverOption: A

The correct is A, because m2 object variables x and y are not assigned so, these have default zero values. so the answer is 100:200:0:0 and you can test the code: public class MyField { int x; int y; public void doStuffy(int x, int y) { x = x; y = this.y; } public void display () { System.out.print(x + " " + y + " : "); } public static void main(String[] args) { MyField m1 = new MyField (); m1.x = 100; m1.y = 200; MyField m2 = new MyField(); m2.doStuffy(m1.x, m1.y); m1.display(); m2.display(); } }

carloswork

Thanks

Joker74Option: A

m2 object variables x and y are not assigned so, these have default zero values. so the answer is 100:200:0:0

shivkumarx

Tested and agreed

RajeevkuamrOption: A

A. 100 200 : 0 0 because x =x; if this.x=x then answer is B

AhmadTechieOption: A

Answer is A

DarGrinOption: A

A is correct

winfred_luOption: A

100 200 : 0 0 :

Kolodets

doStuff method only assign local variables, not affecting instance variables

Vicky_65Option: A

A is the correct one

odzio33Option: A

100 200 : 0 0 : public class MyField { int x; int y; public void doStuffy(int x, int y) { x = x; y = this.y; } public void display () { System.out.print(x + " " + y + " : "); } public static void main(String[] args) { MyField m1 = new MyField (); m1.x = 100; m1.y = 200; MyField m2 = new MyField(); m2.doStuffy(m1.x, m1.y); m1.display(); m2.display(); } }

RajeevkuamrOption: B

B. 100 200 : 100 0

haisacoOption: A

Answer is A.

akbiyikOption: A

100 200 : 0 0 :

carlosworkOption: A

As below (iSnover comment), Answer is A.