package liu0919;
public class Point
{
//属性
private double x;
private double y;
private double d;
//构造方法
Point(double x,double y)
{
this.x=x;
this.y=y;
this.d=x+y;
}
//成员方法
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
}
package liu0919;
public class Ceshi_point {
public static void main(String[] args) {
Point po=new Point(5,6);
System.out.println("原始大小x="+po.getX()+"y="+po.getY());
po.setY(8);
po.setX(2);
System.out.println("点大小x="+po.getX()+"y="+po.getY());
}
}

创建一个Point类,有成员变量x,y,方法getX(),setX(),还有一个构造方 法初始化x和y。创建类主类A来测试它。
原文:http://www.cnblogs.com/liuyanzeng/p/5886621.html