What is the result?

Given:
public class MyField { int x; int y;
public void doStuff(int x, int y) { this.x = x; y = this.y;
>
public void display () {
System.out.print(x + " " + y + " : ");
}
public static void main(String[] args) { MyField ml = new MyField (); ml.x = 100; ml. y = 200;
MyField m2 = new MyField (); m2 .doStuff(ml.x, ml.y); ml.display{); m2.display{);
}
}
What is the result?
A. 100 0 : 100 200:
B. 100 0 : 100 0 :
C. 100200:100 200:
D. 100 200 : 100 0 :

Download Printable PDF. VALID exam to help you PASS.

3 thoughts on “What is the result?

  1. D is correct answer bcs in DoStuf methos this.x = x ; but y = this.y.. it’s reversed … so ==== > m2.y takes the default value 0

  2. D is the correct answer. (I corrected and ran the code.) Note that in doStuff(), y=this.y compiles but the order is reversed (should be this.y=y) and so the y variable remains 0.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.