- /**
- * 引用传递
- * 对象类型采用引用传递方式向方法传递参数
- * 对象类型的变量值存储在"堆"中
- */
- class Student implements Cloneable {
- public String id;
- public String name;
- public Object clone() {
- Student o = null;
- try {
- o = (Student) super.clone();
- } catch (Exception e) {
- throw new java.lang.IllegalStateException("Clone 出错!"+ e.toString());
- }
- return o;
- }
- }
- public class ReferencePass {
- public static void main(String[] args) {
- Student student = new Student();
- student.id = "0001";
- student.name = "Tom";
- new ReferencePass().test(student);
- System.out.println("student.id=" + student.id);
- System.out.println("student.name=" + student.name);
- }
- private void test(Student student) {
- student.id = "0002";
- student.name = "Jike";
- }
- }
JDK6.0学习笔记(四)引用传递
最新推荐文章于 2023-10-30 19:30:56 发布