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") } } }

20th Mar 2021, 1:18 PM
Zotta
Zotta - avatar
7 odpowiedzi
- 4
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(); }
20th Mar 2021, 1:37 PM
Jayakrishna 🇮🇳
+ 9
//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"); } }
4th Sep 2021, 10:56 AM
Fazal Haroon
Fazal Haroon - avatar
+ 1
better is abstract class Animal implements Swimmer, Player { and delete last parentheses } in Cat and Dog class
20th Mar 2021, 1:45 PM
zemiak
+ 1
//100% 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"); } }
25th Jul 2023, 5:39 PM
Dhanuji S Ranasinghe
Dhanuji S Ranasinghe - avatar
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"); } }
23rd Mar 2022, 1:32 PM
Juned Miah
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
9th May 2022, 6:34 AM
U.L.F. Feroza
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{ public void swim(){ System.out.println("Dog is swimming"); } public void play(){ System.out.println("Dog is playing"); } } class Cat extends Animal { public void swim(){ System.out.println("Cat is swimming"); } public void play() { System.out.println("Cat is playing"); } }
15th Mar 2023, 10:16 AM
MOLONAA JOSEPH
MOLONAA JOSEPH - avatar