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