0

Interfaces

You love all animals, and have a dog and a cat as pets. class Main { public static void main(String[] args) { Animal dog = new Dog(); Animal cat = new Cat(); dog.swim(); cat.swim(); dog.play(); cat.play(); } } interface Swimmer { void swim(); } interface Player { void play(); } //implement the Swimmer and the Player interfaces class Animal implements Swimmer, Player{ } abstract class Animal{ } class Dog extends Animal { //Override the swim() and the play() methods @Override public void swim() { System.out.println("Dog is swimming"); } @Override public void play() { System.out.println("Dog is playing"); } } class Cat extends Animal { //Override the swim() and the play() methods @Override public void swim() { System.out.println("Cat is swimming"); } @Override public void play() { System.out.println("Cat is playing"); } } I can't find where is the problem here. it doesn't give any output.

2nd Jul 2021, 1:45 PM
Migel
2 odpowiedzi
+ 1
Migel Create abstract class Animal, define abstract methods and implement Swimmer and Player interface. public abstract class Animal implements Swimmer, Player{ public abstract void swim(); public abstract void play(); }
2nd Jul 2021, 2:04 PM
A͢J
A͢J - avatar
+ 1
You declare Animal class 2 times. Both are not correct way.. remove those and add this : abstract class Animal implements Swimmer, Player{ }
2nd Jul 2021, 2:05 PM
Jayakrishna 🇮🇳