nss
Originally posted by Madan, Gopal:
This is an example of "pass by value" - specifically for primitives.
You have static integer variables x and y - Automatically initialized to their default primitive values - in this case to 0.
Then all you're doing is manipulate the copies of x and y inside various constructors. SCOPE of the intermediate values of x and y are confined to the respective constructors where they are being manipulated.
The moment you come out of all your constructors, back to the main method and call
System.out.println(x + "," + y);
x and y are getting the ORIGINALLY INITIALIZED default values
Hence x = 0 and y = 0.
To confirm, in the declaration of the static int variables x and y, you can explicitly initialize them to any value you want. Those are the exact values you will get in the output.
For e.x. if you say:
static int x = 14, y = 23;
your output will be 14,23
nss
nss
nss
Not like what Madan said that constructors do not return any values.
nss
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |