天天看點

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