Browse Source

添加 'w5/readme shape.txt'

main
dengxitong 1 week ago
parent
commit
64b7033938
  1. 36
      w5/readme shape.txt

36
w5/readme shape.txt

@ -0,0 +1,36 @@
// 父类Shape
class Shape {
public void draw() {
// 默认实现
}
}
// 子类Circle
class Circle extends Shape {
public void draw() {
System.out.println("Drawing a circle");
}
}
// 子类Rectangle
class Rectangle extends Shape {
public void draw() {
System.out.println("Drawing a rectangle");
}
}
// 测试类
class ShapeTest {
// drawShape方法
public static void drawShape(Shape shape) {
shape.draw();
}
public static void main(String[] args) {
Circle circle = new Circle();
Rectangle rectangle = new Rectangle();
drawShape(circle);
drawShape(rectangle);
}
}
Loading…
Cancel
Save