Hi I have following code block
public class Driver {
static String x = "x";
static String y = "y";
public static void main(String[] args) throws Exception {
setX(x);
System.out.println("but x is still "+x);
}
static void setX(String x){
x="a";
System.out.println("now x should be = "+x);
}
}
and this prints
now x should be = a
but x is still x
I was hoping to get
now x should be = a
but x is still a
I know there are ways to get what I want,but please answer why this does not work.
1 Answer