From eac3b3bfe320cceeb58f6248d694a27baeba7ecd Mon Sep 17 00:00:00 2001 From: dengxitong <2452879460@qq.com> Date: Wed, 8 Apr 2026 20:21:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'w5/shape.java'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w5/shape.java | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 w5/shape.java diff --git a/w5/shape.java b/w5/shape.java new file mode 100644 index 0000000..9246763 --- /dev/null +++ b/w5/shape.java @@ -0,0 +1,29 @@ +class Shape { + public void draw() {} +} + +class Circle extends Shape { + public void draw() { + System.out.println("Drawing a circle"); + } +} + +class Rectangle extends Shape { + public void draw() { + System.out.println("Drawing a rectangle"); + } +} + +class ShapeTest { + 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); + } +} \ No newline at end of file