当前位置 : 主页 > 编程语言 > java >

java 类和方法引用

来源:互联网 收集:自由互联 发布时间:2021-06-28
gistfile1.txt public class Point { int x=0; int y =0; Point() { System.out.println(" I'm Point()"); } Point(int x, int y) { this.x = x; this.y = y; System.out.println("I'm Point(int x,inty)"); } /** * 显示当前点的坐标 * @param args
gistfile1.txt
public class Point {

    int x=0;
    int y =0;

    Point() {
        System.out.println(" I'm Point()");

    }

    Point(int x, int y) {
        this.x = x;
        this.y = y;
        System.out.println("I'm Point(int x,inty)");

    }


    /**
     * 显示当前点的坐标
     * @param args
     */
    int displayMyCoordinate(){
        System.out.println("当前点的坐标是:" + this.x  + ","+ this.y);
        return 1;

    }

    /**
     * 获得某两点之间的中点。
     * @param args
     */
    Point midpoint(Point A,Point B){
        int x = (A.x + B.x)/2;
        int y = (A.y + B.y)/2;
        Point p = new Point(x,y);
        return p;
    }



    public static void main(String[] args) {
        Point p = new Point();
        Point p2 = new Point(2, 2);
        System.out.println(p2.displayMyCoordinate());
        System.out.println(p2.x);

    }

}
网友评论