From 24261300b8fbed44664b34118ec3c4732353e867 Mon Sep 17 00:00:00 2001 From: HuangZhikai <386754646@qq.com> Date: Wed, 15 Apr 2026 16:12:23 +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/Animal.java | 3 +++ w6/Cat.java | 6 ++++++ w6/Dog.java | 11 +++++++++++ w6/Main.java | 20 ++++++++++++++++++++ w6/Swimmable.java | 3 +++ 5 files changed, 43 insertions(+) create mode 100644 w6/Animal.java create mode 100644 w6/Cat.java create mode 100644 w6/Dog.java create mode 100644 w6/Main.java create mode 100644 w6/Swimmable.java diff --git a/w6/Animal.java b/w6/Animal.java new file mode 100644 index 0000000..95b6c3c --- /dev/null +++ b/w6/Animal.java @@ -0,0 +1,3 @@ +public abstract class Animal{ + public abstract void makeVoice(); +} \ No newline at end of file diff --git a/w6/Cat.java b/w6/Cat.java new file mode 100644 index 0000000..f249bc0 --- /dev/null +++ b/w6/Cat.java @@ -0,0 +1,6 @@ +public class Cat extends Animal{ + @Override + public void makeVoice(){ + System.out.println("曼波,曼波,哦马资历———曼波"); + } +} diff --git a/w6/Dog.java b/w6/Dog.java new file mode 100644 index 0000000..f6851fe --- /dev/null +++ b/w6/Dog.java @@ -0,0 +1,11 @@ +public class Dog extends Animal implements Swimmable{ + @Override + public void makeVoice(){ + System.out.println("汪汪汪"); + } + @Override + public void swim(){ + System.out.println("狗会游泳"); + } + +} diff --git a/w6/Main.java b/w6/Main.java new file mode 100644 index 0000000..ee6af96 --- /dev/null +++ b/w6/Main.java @@ -0,0 +1,20 @@ +public class Main { + public void main(){ + Animal cat = new Cat(); + Animal dago = new Dog(); + cat.makeVoice(); + dago.makeVoice(); + if(cat instanceof Swimmable){ + System.out.println("猫会游泳"); + } + else{ + System.out.println("猫不会游泳"); + if (dago instanceof Swimmable){ + System.out.println("大狗会游泳"); + } + else{ + System.out.println("大狗不会游泳"); + } + } + } +} diff --git a/w6/Swimmable.java b/w6/Swimmable.java new file mode 100644 index 0000000..77cbc2b --- /dev/null +++ b/w6/Swimmable.java @@ -0,0 +1,3 @@ +public interface Swimmable { + public abstract void swim(); +}