From 2dc34cbbd2cafef28d4da943fbf6ca63af83576f Mon Sep 17 00:00:00 2001 From: Jiayuheng Date: Wed, 8 Apr 2026 18:30:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'w5'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w5/ShapeDemo.java | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 w5/ShapeDemo.java diff --git a/w5/ShapeDemo.java b/w5/ShapeDemo.java new file mode 100644 index 0000000..5c9c8ca --- /dev/null +++ b/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); + } +} \ No newline at end of file