Browse Source

上传文件至 'w5'

main
Jiayuheng 1 week ago
parent
commit
2dc34cbbd2
  1. 40
      w5/ShapeDemo.java

40
w5/ShapeDemo.java

@ -0,0 +1,40 @@
class Shape {
public void draw() {
System.out.println("Drawing a shape");
}
}
class Circle extends Shape {
@Override
public void draw() {
System.out.println("Drawing a circle");
}
}
class Rectangle extends Shape {
@Override
public void draw() {
System.out.println("Drawing a rectangle");
}
}
public class ShapeDemo {
public static void drawShape(Shape s) {
s.draw();
}
public static void main(String[] args) {
Shape shape = new Shape();
Circle circle = new Circle();
Rectangle rectangle = new Rectangle();
System.out.println("Testing Shape:");
drawShape(shape);
System.out.println("\nTesting Circle:");
drawShape(circle);
System.out.println("\nTesting Rectangle:");
drawShape(rectangle);
}
}
Loading…
Cancel
Save