1、编写一个无参的构造函数;
2、编写一个有参的构造函数;
3、在主函数中调用无参的构造函数生成圆的实例c1,调用有参的构造函数生成圆的实例c2,调用实例方法判断c1和c2是否相重叠。
public class point {
int x,y;
/*point(int a,int b)
{
x=a;
y=b;
}*/
}
public class Circle {
point a=new point();
int radius;
Circle() {
//a.x=30;
a.x=30;
a.y=30;
radius=10;
}
Circle(int xx,int yy,int r)
{
a.x=xx;
a.y=yy;
radius=r;
}
void compare(Circle b)
{
if(a.x==b.a.x&&a.y==b.a.y&&radius==b.radius)
System.out.println("这两个圆是重叠的!!!");
else
System.out.println("这两个圆不是重叠的!!!");
}
}
public class TestCicle {
public static void main(String[] args) {
Circle cicle1=new Circle();
Circle cicle2=new Circle(30,30,10);
Circle cicle3=new Circle(40,30,10);
cicle1.compare(cicle2);
cicle1.compare(cicle3);
cicle2.compare(cicle3);
}
}