When I watched code examples in Java, I saw a strange code:
public class Application {
public static void main(String[] args) {
String[] x = {"A"};
String[] y = x;
x[0] = "B";
System.out.print(x[0] + " " + y[0]);
}
}
And I don't understand, why the result "B B" is correct? When I created and initialized an arrays x and y and assigned zero element of array x is equal to B, I think that an answer must be "B A".
No comments:
Post a Comment