java 对象等于_java 之类对象等于对象 | 学步园
/*
* 使per2等于per1,其實是引用,當改變per2的屬性時,實質上是改變了per2,per1所共同指向的堆內存里的數據。
*/
package StringClass;
/**
*
* @author zendao
*/
public class CopyAClass {
public static void main(String args[]) {
NewPeople per1 = new NewPeople("lucy", 22); // declare two entity
NewPeople per2;
per2 = per1; // per2 equal per1
per2.setName("James"); // change the attribute of per2
per1.getInfo(); // display and check the result
per2.getInfo();
}
}
/**
* test class
*
* @author zendao
*/
class NewPeople {
private String name; // define test attributes
private int age;
/**
* a constructor
* @param name
* @param age
*/
public NewPeople(String name, int age) {
this.name = name;
this.age = age;
}
/**
* this method for printing the result
* @return
*/
public String getInfo() {
System.out.println("Name of this is :" + this.name + ",and age is :" + this.age);
return null;
}
/**
* this method is for change the attribute
* @param name
*/
public void setName(String name) {
this.name = name;
}
}
總結
以上是生活随笔為你收集整理的java 对象等于_java 之类对象等于对象 | 学步园的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 5.6.22编译_salts
- 下一篇: mysql随机选择记录表_Mysql表中