import java.util.*;
import java.math.*;
/**
* 构造方法详解,构造方法重载
* @author 110
*
*1:通过new关键字调用!
*2:构造器虽然有返回值,但是不能定义返回值类型(返回值的类型肯定是本类)
* 不能再构造器里面使用return返回某个值
*3:如果我们没有定义构造器,则编译器会自动定义一个无参的共组凹函数。
* 如果已经定义,则编译器不会自动添加。
*4:构造器的方法名必须和类名一致
*/
class Point1{
double x,y,z;
public Point1(double x1,double y1) {
x=x1;
y=y1;
}
public Point1(double x1) {
x=x1;
}
public Point1(double x1,double x2,double x3) {
super();//构造方法的第一句 总是super,如果不写,编译器帮你自动加。
x=x1;
y=x2;
z=x3;
}
double getpoint(Point1 p) {
return Math.sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));
}
}
public class Point {
public static void main(String[] args) {
Point1 i = new Point1(5.0);
Point1 i2 = new Point1(5.0,6.0);
Point1 i3 = new Point1(5.0,6.0,7.0);//根据不同类型做不同处理,方法名称相同,形参列表不同
Point1 p1= new Point1(3.0,4.0);
Point1 p2=new Point1(0,0);
System.out.println(p1.getpoint(p2));
}
}