Java Interface exercise Animal Lovers | Sololearn: Learn to code for FREE!

+1

Java Interface exercise Animal Lovers

Hi, I am doing the Java interface exercise Animal Lovers. When I execute the code it gets no input and of course no output. Looking a the main method, I am thinking it should have executed since I did override the the methods, but I guess I am wrong This is what I have ``` 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{ public abstract void play(); public abstract void swim(); } 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"); } } } ``` Where am i going wrong with this.

5/12/2021 3:02:07 PM

Curtis Chadwell

3 Answers

New Answer

+1

It's working.. edit: try make main() public. public 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{ public abstract void play(); public abstract void swim(); } 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"); } } //}

+1

package html; 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{ public abstract void swim(); public abstract void play(); } 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 public void swim() { System.out.println("Cat is swimming"); } @Override public void play() { System.out.println("Cat is playing"); } //Override the swim() and the play() methods } //100%

+1

//Animal lovers java challenge 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"); } } //Good luck everyone