package com.wo;import android.app.Activity;
import android.os.Bundle;
import android.util.Log;public class WoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Point p1=new Point(1,1);
Point p2=p1;
p2.setX(2);
Log.v("p1 x", p1.x+"");
}
class Point{
int x;
int y;
public Point(int x, int y) {
super();
this.x = x;
this.y = y;
}
/**
* @return the x
*/
public int getX() {
return x;
}
/**
* @param x the x to set
*/
public void setX(int x) {
this.x = x;
}
/**
* @return the y
*/
public int getY() {
return y;
}
/**
* @param y the y to set
*/
public void setY(int y) {
this.y = y;
}
@Override
public boolean equals(Object o) {
Point p=(Point)o;
if(this.x==p.x&&this.y==p.y){
return true;
}
return false;
}
}
}
输出结果为2,请问我要输入1怎么改?
也就是怎么进行类的对象进行赋值,以得到两个相同值的不同对象?
然后使用Point p1=new Point(1,1);
Point p2=p1.clone()就可以实现克隆。这样不管p2的值怎么改都不会影响p1了。
希望我的回答对你有帮助