0
点赞
收藏
分享

微信扫一扫

JAVA|Point类

westfallon 2022-04-19 阅读 94
java后端

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;
    }
}
举报

相关推荐

0 条评论