java的一个基础题

来源:百度知道 编辑:UC知道 时间:2024/09/23 10:27:36
定义一个圆类,重载构造函数,以生成不同的圆。

class Round{
private double area;
public Round(double r){
System.out.println("正圆");
}
public Round(double r1,round r2){
System.out.println("椭圆");
}

重载设置其半径值,通过修改半径值达到生成不同圆的目的circle(double i),i就是你的半径

这位朋友,圆还分几种圆吗,半圆,什么的。只能是定义一个类,然后重载类的的构造函数,以计算不同的类的周长或面积。

下面我只写了两下圆类的重载的构造函数。
public class CPoint
{
private float r = 0;
private float leight = 0,weight = 0;
final double PI = 3.1415; //PI充当∏。
public CPoint(float R)
{
r = R;
}
public float atea()
{
return PI*r*r; //调用返回圆的面积
}
public CPoint( flaot a,float b)
{
leight = a;
weight = b;
}
public float Atea()
{
return leight*weight; //调用返回距形的面积。
}
public static void main(String[] args)
{
CPoint point1 = new CPoint(5.1); //初始化圆的半径
CPoint point2 = new CPo