JAVA|Point类

Point类

创建一个Point类,有成员变量x,y,方法getX(),setX(),还有一个构造方
法初始化x和y。创建类主类A来测试它。

import java.util.Scanner;
public class shiyan12 {
    public static void main(String[] arg){
        Point point=new Point(34,46);
        System.out.println("get x="+point.getX()+"y="+point.getY());

        point.setY(21);
        point.setX(16);
        System.out.println("set x="+point.getX()+"y="+point.getY());


    }
}
class Point{
   double x;
   double y;
    Point(double x,double y)
    {
        this.x=x;
        this.y=y;
    }
    
    double getX() {
        return x;
    }
    
    void setX(double x) {
        this.x = x;
    }
    
    double getY() {
        return y;
    }

    void setY(double y) {
        this.y = y;
    }
}

你可能感兴趣的:(JAVA,java,point)