From 64b7033938954aa5c03afdd978082dd4e0bfe735 Mon Sep 17 00:00:00 2001 From: dengxitong <2452879460@qq.com> Date: Wed, 8 Apr 2026 20:24:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'w5/readme=20shape.txt'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w5/readme shape.txt | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 w5/readme shape.txt diff --git a/w5/readme shape.txt b/w5/readme shape.txt new file mode 100644 index 0000000..75a589f --- /dev/null +++ b/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); + } +} \ No newline at end of file