shape.java
来自「java 进阶专用。」· Java 代码 · 共 36 行
JAVA
36 行
// Page 101
abstract class Shape {
abstract double area();
}
class Circle extends Shape {
final double radius;
Circle(double radius) { this.radius = radius; }
double area() { return Math.PI * radius*radius; }
}
class Rectangle extends Shape {
final double length;
final double width;
Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
double area() { return length * width; }
}
// Page 102
class Square extends Rectangle {
Square(double side) {
super(side, side);
}
double side() {
return length; // or equivalently, width
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?