From 39d09ae0578053b2536356941d09ca9126e64067 Mon Sep 17 00:00:00 2001 From: Fuyuxinge <1876397977@qq.com> Date: Sun, 12 Apr 2026 22:03:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w6/Animal.java | 0 w6/AnimalTest.java | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 w6/Animal.java create mode 100644 w6/AnimalTest.java diff --git a/w6/Animal.java b/w6/Animal.java new file mode 100644 index 0000000..e69de29 diff --git a/w6/AnimalTest.java b/w6/AnimalTest.java new file mode 100644 index 0000000..457d59b --- /dev/null +++ b/w6/AnimalTest.java @@ -0,0 +1,27 @@ +package w6; + +public class AnimalTest { + public static void main(String[] args) { + Animal dog = new Dog(); + Animal cat = new Cat(); + + + System.out.println("动物叫声测试"); + dog.makeSound(); + cat.makeSound(); + + + System.out.println("游泳能力测试"); + if (dog instanceof Swimmable) { + ((Swimmable) dog).swim(); + } else { + System.out.println("这只动物不会游泳"); + } + + if (cat instanceof Swimmable) { + ((Swimmable) cat).swim(); + } else { + System.out.println("猫不会游泳"); + } + } +} \ No newline at end of file