Animal lovers, java | Sololearn: Learn to code for FREE!

0

Animal lovers, java

I am not sure what I have to write inside the abstract class. 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 abstract class Animal{ public void swim (); public void play(); } 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") } } }

3/20/2021 1:18:46 PM

Zotta

5 Answers

New Answer

-3

Zotta Add abstract for abstract methods.. abstract class Animal{ abstract public void swim(); abstract public void play(); } And also you are missing ; in line51. edit : no use of interface. you can remove. if you want use interface too, add implementations: abstract class Animal implements Swimmer, Players { abstract public void swim(); //public void swim(){ } also works but better to make abstract here abstract public void play(); }

+4

//Please Subscribe to My Youtube Channel //Channel Name: Fazal Tuts4U 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"); } }

0

better is abstract class Animal implements Swimmer, Player { and delete last parentheses } in Cat and Dog class

0

// Solution 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{ abstract public void swim(); abstract public void play(); } 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"); } }

0

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"); } } // this is working