引用是java的精髓所在,类似于C++的指针,但是比指针简单。 引用最关键的还是关键字 :new。
例:
class Person{
String name ;
int age;
public void say()
{
System.out.println("我的名字是:"+name+","+age+"");
}
}
public class hello {
public static void main(String[] args) {
// TODO Auto-generated method stub
Person per1 = new Person();
Person per2 = null;
per2 = per1 ; //引用传递
per1.name = "lq";
per1.age = 24;
per1.say();
per2.name = "zq";
per2.age =22;
per2.say();
}
}