为什么我长方形的算不出来啊
abstract class shapeSX {
abstract float getArea();
abstract float getPerimeter();
}
class CircleSX extends shapeSX {
float radius;
CircleSX(float number) {
radius = number;
}
protected float getArea() {
return 3.14f * radius * radius;
}
protected float getPerimeter() {
return 2 * 3.14f * radius;
}
}
class RectangleSX extends shapeSX {
float width;
float length;
RectangleSX(float width, float height) {
this.width = width;
this.length = length;
}
float getArea() {
return width * length;
}
float getPerimeter() {
return 2 * (width * length);
}
}
class TextAbstract {
public static void main(String[] args) {
System.out.println("2.获得长方形的面积与周长");
RectangleSX rectangle = new RectangleSX(5, 6);
System.out.printf("长方形的面积:%s%n", rectangle.getArea());
System.out.printf("长方形的周长:%s%n", rectangle.getPerimeter());
System.out.println("1.获得圆的面积与周长");
CircleSX circle = new CircleSX(4);
System.out.printf("圆的面积:%s%n", circle.getArea());
System.out.printf("圆的周长:%s%n", circle.getPerimeter());
}
}
最后
以上就是朴素小甜瓜最近收集整理的关于Java抽象类编程问题能解答一下吗的全部内容,更多相关Java抽象类编程问题能解答一下吗内容请搜索靠谱客的其他文章。
发表评论 取消回复