public class Employee {
private String name;
private double salary;
public Employee(String n,double s){
name = n;
salary =s;
}
public class Test {
public static void main(String[] args) {
Employee [] abc= new Employee[3];
abc [0]= new Employee("Alice", 70000);
abc [1] = new Employee("Bob",60000);
abc [2]= new Employee("Plice", 50000);
abc [2]=abc[0];
abc [0]=abc[1];
abc[1]=abc [2];
for(Employee e:abc){
System.out.println(e.getName()+"\t"+e.getSalary());
}
}
}
输出结果:
Bob 60000.0
Alice 70000.0
Alice 70000.0
不知道结果为啥是这样
最后不应该都是指向同一个引用值么,但又不知道应该指向哪个引用值了......
这个真心看不懂,求高手一步一步讲解
堆,栈,引用值
------解决方案--------------------
看图