From dc2eb555f78ab260a936d597a95367a894378d19 Mon Sep 17 00:00:00 2001 From: Gaoyuduo Date: Thu, 7 May 2026 15:33:58 +0800 Subject: [PATCH] =?UTF-8?q?W5-=E9=AB=98=E9=92=B0=E9=93=8E-202506050304?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 5.1.3.txt | 9 +++++++++ 5.1.4.txt | 19 +++++++++++++++++++ 5.2.1.txt | 6 ++++++ 新建 文本文档.txt | 9 +++++++++ 无标题.txt | 9 +++++++++ 5 files changed, 52 insertions(+) create mode 100644 5.1.3.txt create mode 100644 5.1.4.txt create mode 100644 5.2.1.txt create mode 100644 新建 文本文档.txt create mode 100644 无标题.txt diff --git a/5.1.3.txt b/5.1.3.txt new file mode 100644 index 0000000..8d77d38 --- /dev/null +++ b/5.1.3.txt @@ -0,0 +1,9 @@ +/** + * 矩形:重写draw()方法 + */ +public class Rectangle extends Shape { + @Override + public void draw() { + System.out.println("绘制矩形 🟦"); + } +} \ No newline at end of file diff --git a/5.1.4.txt b/5.1.4.txt new file mode 100644 index 0000000..2599244 --- /dev/null +++ b/5.1.4.txt @@ -0,0 +1,19 @@ +/** + * 测试类:包含drawShape()方法,统一调用draw() + */ +public class TestShape { + // 统一绘制图形的方法 + public static void drawShape(Shape s) { + s.draw(); // 多态调用:执行子类重写的draw() + } + + public static void main(String[] args) { + // 创建不同图形对象 + Shape circle = new Circle(); + Shape rectangle = new Rectangle(); + + // 调用统一方法绘制 + drawShape(circle); + drawShape(rectangle); + } +} \ No newline at end of file diff --git a/5.2.1.txt b/5.2.1.txt new file mode 100644 index 0000000..a0601e0 --- /dev/null +++ b/5.2.1.txt @@ -0,0 +1,6 @@ +/** + * 交通工具抽象类:定义抽象方法run() + */ +public abstract class Vehicle { + public abstract void run(); +} \ No newline at end of file diff --git a/新建 文本文档.txt b/新建 文本文档.txt new file mode 100644 index 0000000..d8f58aa --- /dev/null +++ b/新建 文本文档.txt @@ -0,0 +1,9 @@ +/** + * 图形父类:定义draw()方法规范 + */ +public class Shape { + // 绘制方法(父类默认实现) + public void draw() { + System.out.println("绘制基础图形"); + } +} \ No newline at end of file diff --git a/无标题.txt b/无标题.txt new file mode 100644 index 0000000..bea5b1e --- /dev/null +++ b/无标题.txt @@ -0,0 +1,9 @@ +/** + * 圆形:重写draw()方法 + */ +public class Circle extends Shape { + @Override + public void draw() { + System.out.println("绘制圆形 ⭕"); + } +} \ No newline at end of file