Because primitive types pass by value so you pass a copy of variable . With reference type like array you pass copy of refernce so i expect output to be 0 0 1, but answer here is 1 0 1. Can pls explain.
Little scope problem here a is an instance member which means that if you modify it within a method its value will be changed. You also pass b by value but you also name the argument "b" so inside the method b will be the argument and not the instance member and that's why the value of b (the instance member) does not change. If you refer to b inside the method then the actual b you are working on is the argument and not the instance member. HIH ------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform
My Linked In
posted 18 years ago
Ok, I see we really do this.a = 1!! which mean we change actual object. b is a copy which mean we never change the actual variable, we modify copy of the variable. With array which is reference type - we assign a new value to the first elemnt in the array.
I am a man of mystery. Mostly because of this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!