You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pangyaxuan
92e49b2f14
上传文件至 'W5'
package w5;
// 基础题:Shape类及其子类
abstract class Shape {
public abstract void draw();
}
class Circle extends Shape {
private double r;
public Circle(double r) {
this.r = r;
}
@Override
public void draw() {
System.out.println("绘制圆形,半径:" + r);
}
}
class Rectangle extends Shape {
private double width;
private double height;
public Rectangle(double width, double height) {
this.width = width;
this.height = height;
}
@Override
public void draw() {
System.out.println("绘制矩形,宽:" + width + ",高:" + height);
}
}
// 工具类
class ShapeUtil {
public static void drawShape(Shape s) {
s.draw();
}
}
// 主类
public class PolymorphismDemo {
public static void main(String[] args) {
System.out.println("=== 基础题测试 ===");
// 测试Shape类
Shape circle = new Circle(5);
Shape rectangle = new Rectangle(4, 6);
ShapeUtil.drawShape(circle);
ShapeUtil.drawShape(rectangle);
}
}
|
2 weeks ago |
|
W4
|
上传文件至 'W4'
|
3 weeks ago |
|
W5
|
上传文件至 'W5'
|
2 weeks ago |
|
README.md
|
Initial commit
|
2 months ago |
|
W1.zip
|
上传文件至 ''
|
1 month ago |
|
W2
|
添加 'W2'
|
1 month ago |
|
W3
|
添加 'W3'
|
4 weeks ago |
|
hello wo r l d
|
添加 'hello wo r l d'
|
1 month ago |