This week's book giveaway is in the Reactive Progamming forum. We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line! See this thread for details.
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
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.
Yeast devil! Back to the oven that baked you! And take this tiny ad too: