1、 编写一个无参的构造函数

2、 编写一个有参的构造函数

3、 在主函数中调用无参的构造函数生成圆的实例c1,调用有参的构造函数生成圆的实例c2,调用实例方法判断c1c2是否相重叠。

public class Circle {

 

double x,y,r;

public Circle(double x,double y,double r){

this.x=x;

this.y=y;

this.r=r;

}

public Circle (){

x=1.0;

y=1.0;

r=1.0;

}

void test(Circle a){

if(x==a.x&&y==a.y&&r==a.r)

System.out.println("圆c1与c2重叠");

else

System.out.println("圆c1与c2不重叠");

}

 

public static void main(String[] args) {

Circle c1=new Circle();

Circle c2=new Circle(1.0,2.0,1.0);

c1.test(c2);

 

}

 

}

以Point类为基础,定义一个平面中的Circle类:


相关文章:

  • 2022-12-23
  • 2022-01-01
  • 2021-09-23
  • 2022-12-23
  • 2021-05-21
  • 2021-07-12
  • 2021-11-18
  • 2022-12-23
猜你喜欢
  • 2021-04-17
  • 2021-11-14
  • 2021-09-12
  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
  • 2021-10-23
相关资源
相似解决方案