0

Can anyone help me with Java Course

I can't seem to go past Java Practice 46.2

23rd Feb 2023, 9:32 AM
Maposa Lyson
4 Answers
+ 3
What is the task/question? Can you copy what you've written into a codebit in the code playground and attach it here using the plus ➕ button?
23rd Feb 2023, 9:54 AM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Why do you added the 2nd time main class inside cat class? Remove those last line from "public class program: ... .. " Just put a } brace.
23rd Feb 2023, 3:56 PM
Jayakrishna 🇼🇳
0
This is the task You love all animals, and have a dog and a cat as pets. The program you are given defines an abstract class Animal, and has Dog & Cat classes inherited from it. Implement the Swimmer and Player interface and override their methods swim() and play(), so that the given method calls output the following messages: swim(): Dog => "Dog is swimming" Cat => "Cat is swimming" play(): Dog => "Dog is playing" Cat => "Cat is playing"
23rd Feb 2023, 2:29 PM
Maposa Lyson
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"); } //Override the swim() and the play() methods } } class Cat extends Animal { public void swim(){ System.out.println("Cat is swimming"); } public void play(){ System.out.println("Cat is playing"); } public class Program: public static void main(String[] args) { Cat c = new Cat(); c.swim(); } //Override the swim() and the play() methods } }
23rd Feb 2023, 2:29 PM
Maposa Lyson