package hiwari;
/*
* 定义长方形(Rectagle)类,成员变量:宽(width)和高(height)
* 成员方法:
* setvalue(),用于给成员变量赋初值;
* printarea(),用于输出长方形面积。
* 在主函数中创建Rectagle类对象r,通过setvalue给r赋初值(3,5)并输出面积
* */
public class Rectagle {
double width,height;
void setvalue(double a,double b){
width=a;
height=b;
}
void printarea()
{
System.out.print(width*height);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Rectagle bb=new Rectagle();
bb.setvalue(3, 5);
bb.printarea();
}
}
【水汐のjava】定义长方形(Rectagle)类,成员变量:宽(width)和高(height)成员方法:
最新推荐文章于 2023-03-08 08:56:14 发布