📄 testshape.java
字号:
abstract class Shape {
abstract double area();
}
class Circle extends Shape {
public int r;
Circle(int r) {
this.r = r;
}
public double area() {
return 3.14 * r * r;
}
}
class Rectangle extends Shape {
public int width, height;
Rectangle(int w, int h) {
width = w;
height = h;
}
public double area() {
return width * height;
}
}
class Test {
public static void main(String[] args) {
double area_total = 0.0;
Shape[] shape = { new Circle(2), new Rectangle(5, 2), new Circle(3) };
for (int i = 0; i < shape.length; i++) {
area_total += shape[i].area();
}
System.out.println("Area = " + area_total);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -