From 00b8feb0222702e6176f7409c3a433eb57df2ebd Mon Sep 17 00:00:00 2001 From: yuangandong <1975775515@qq.com> Date: Mon, 25 May 2026 10:52:34 +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'w6'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w6/1 | 3 +++ w6/2 | 6 ++++++ w6/3 | 11 +++++++++++ w6/4 | 20 ++++++++++++++++++++ w6/5 | 3 +++ 5 files changed, 43 insertions(+) create mode 100644 w6/1 create mode 100644 w6/2 create mode 100644 w6/3 create mode 100644 w6/4 create mode 100644 w6/5 diff --git a/w6/1 b/w6/1 new file mode 100644 index 0000000..10202e1 --- /dev/null +++ b/w6/1 @@ -0,0 +1,3 @@ +public abstract class Animal { + public abstract void makeSound (); +} \ No newline at end of file diff --git a/w6/2 b/w6/2 new file mode 100644 index 0000000..9fe80ab --- /dev/null +++ b/w6/2 @@ -0,0 +1,6 @@ +public class Cat extends Animal{ + @Override + public void makeSound() { + System.out.println("猫:喵喵喵"); + } +} \ No newline at end of file diff --git a/w6/3 b/w6/3 new file mode 100644 index 0000000..af8b7b6 --- /dev/null +++ b/w6/3 @@ -0,0 +1,11 @@ +public class Dog extends Animal implements Swimmable{ + @Override + public void makeSound() { + System.out.println("狗:汪汪汪"); + } + + @Override + public void swim() { + System.out.println("狗会游泳"); + } +} \ No newline at end of file diff --git a/w6/4 b/w6/4 new file mode 100644 index 0000000..ad7f4a0 --- /dev/null +++ b/w6/4 @@ -0,0 +1,20 @@ +public class Main { + 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(); + } + if (cat instanceof Swimmable){ + ((Swimmable) cat).swim(); + } else { + System.out.println("猫不会游泳"); + } + } +} \ No newline at end of file diff --git a/w6/5 b/w6/5 new file mode 100644 index 0000000..26c5a27 --- /dev/null +++ b/w6/5 @@ -0,0 +1,3 @@ +public interface Swimmable { + void swim(); +} \ No newline at end of file