计算圆形和长方形的面积

来源:互联网 发布:mac 安装anywhere 编辑:程序博客网 时间:2024/04/29 14:01
public class AA {       //创建类AA    final float PI=3.14f;    int r;    int width,height;    float area;             //定义变量    void AA(int r)    {        area=PI*r*r;        System.out.println("圆的面积:"+area);//定义含有一个参数的方法AA(),参数为圆的半径    }    void AA(int width,int height)    {        area=width+height;        System.out.println("长方形的面积:"+area);//定义含有一个参数的方法AA(),参数为长方形的长和宽    }    public static void main(String[] args) {        // TODO 自动生成的方法存根        AA Shape=new AA();    //定义属于类AA的对象Shape        Shape.AA(6);        Shape.AA(7,9);//通过对象Shaped调用方法AA     }}

结果为:
这里写图片描述

知识要点:
1.方法重载

原创粉丝点击