?? 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 + -