From 06cfc07fe1e9de8b82b9eb33f567d6bd583127ed Mon Sep 17 00:00:00 2001 From: wangbo <1248863822@qq.com> Date: Mon, 13 Apr 2026 20:42:02 +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/Main.java | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 w6/Main.java diff --git a/w6/Main.java b/w6/Main.java new file mode 100644 index 0000000..36a9a0d --- /dev/null +++ b/w6/Main.java @@ -0,0 +1,37 @@ +abstract class Animal { + abstract void makeSound(); +} + +interface Swimmable { + void swim(); +} + +class Dog extends Animal implements Swimmable { + public void makeSound() { + System.out.println("Woof!"); + } + + public void swim() { + System.out.println("Dog is swimming!"); + } +} + +class Cat extends Animal { + public void makeSound() { + System.out.println("Meow!"); + } +} + +public class Main { + public static void main(String[] args) { + Animal myDog = new Dog(); + Animal myCat = new Cat(); + + myDog.makeSound(); + myCat.makeSound(); + + if (myDog instanceof Swimmable) { + ((Swimmable) myDog).swim(); + } + } +} \ No newline at end of file