I have this piece of code.
public class Q {
static int x = 11;
private int y = 33;
public static void main(String args[]) {
Q q = new Q();
q.call(5, 555555);
System.out.println("Value of x " + q.x);
System.out.println("Value of y " + q.y);
}
public void call(int x, int y) {
Q q = new Q();
this.x = x;
this.y = y;
System.out.println("Output: " + x);
System.out.println("Output: " + y);
System.out.println("----------------------------");
System.out.println("Output: " + Q.x);
System.out.println("Output: " + q.x);
System.out.println("Output: " + q.y); // why this is still producing 33 and not 555555
System.out.println("Output: " + y);
System.out.println("----------------------------");
}
}
It produces following output:
Output: 5
Output: 555555
----------------------------
Output: 5
Output: 5
Output: 33
Output: 555555
----------------------------
Value of x 5
Value of y 555555
I understand everything in above output except see the question as comment in above code?
Thanks,
Al
public class Q {
static int x = 11;
private int y = 33;
public static void main(String args[]) {
Q q = new Q();
q.call(5, 555555);
System.out.println("Value of x " + q.x);
System.out.println("Value of y " + q.y);
}
public void call(int x, int y) {
Q q = new Q();
this.x = x;
this.y = y;
System.out.println("Output: " + x);
System.out.println("Output: " + y);
System.out.println("----------------------------");
System.out.println("Output: " + Q.x);
System.out.println("Output: " + q.x);
System.out.println("Output: " + q.y); // why this is still producing 33 and not 555555
System.out.println("Output: " + y);
System.out.println("----------------------------");
}
}
It produces following output:
Output: 5
Output: 555555
----------------------------
Output: 5
Output: 5
Output: 33
Output: 555555
----------------------------
Value of x 5
Value of y 555555
I understand everything in above output except see the question as comment in above code?
Thanks,
Al