0

Can you tell me what the problem is.. expected output "Dog is swimming, Dog is playing, Cat is swimming, Cat is playing"vertical

class Main { public static void main(String[] args) { Animal dog = new Dog(); Animal cat = new Cat(); dog.swim(); dog.play(); cat.swim(); cat.play(); } } interface Swimmer { void swim(); } interface Player { void play(); } //implement the Swimmer and the Player interfaces abstract class Animal implements Swimmer, Player{ } class Dog extends Animal { //Override the swim() and the play() methods public void swim() { System.out.println("Dog is swimming"); } public void play() { System.out.println("Dog is playing"); } } } class Cat extends Animal { //Override the swim() and the play() methods public void swim() { System.out.println("Cat is swimming"); } public void play() { System.out.println("Cat is playing"); } } }

16th Jul 2022, 7:42 AM
Jommiel Cunanan
1 Odpowiedź
+ 1
You have extra } braces after dog, cat classes. Remove those. it works fine then.
16th Jul 2022, 8:28 AM
Jayakrishna 🇮🇳