1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
package 面向对象;
class Point{ double x,y; public Point(double x,double y) { this.x = x; this.y = y; return; } public Point() { } public double getDitance(Point p) { System.out.println("传入对象的地址:"+p); return Math.sqrt((this.x-p.x)*(this.x-p.x)+(this.y-p.y)*(this.y-p.y)); } }
public class TestConstructor { public static void main(String[] args) { Point a = new Point(3.0,4.0); Point b = new Point(0.0,0.0); System.out.println("创建的对象的地址:"+b); System.out.println(a.getDitance(b)); } }
|