//定义一个图形类及其子类(三角形类和矩形类),分别计算其面积和周长。
package JAVA;
class Rectangle {
private int width;
private int length;
public Rectangle(int width,int length) {
super();
this.width = width;
this.length = length;
}
public int getPerimeter(){
return this.width *2 + this.length *2;
}//获得周长
public int getArea(){
return this.width * this.length;
}//面积
}//三角形类
class Triangle {

该博客介绍了如何在JAVA编程中定义一个图形基类,并创建其两个子类——三角形类和矩形类,详细讲解了如何实现计算各自面积和周长的方法。
最低0.47元/天 解锁文章
3446

被折叠的 条评论
为什么被折叠?



