0

no output

class soloLearn11 { 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 {-----------------> I have a problem on this ,,it cause error protected abstract void swim(); protected abstract void play(); } class Dog extends Animal { // Override the swim() and the play() methods @Override protected void swim() { System.out.println("Dog is swimming"); } @Override protected void play() { System.out.println("Dog is playing"); } } class Cat extends Animal { // Override the swim() and the play() methods @Override protected void swim() { System.out.println("Cat is swimming"); } @Override protected void play() { System.out.println("Cat is playing"); } }

26th Apr 2021, 4:33 AM
lordzrealm
lordzrealm - avatar
3 Answers
0
The methods shld be made public when you override them.. Like, @Override public void swim() { ....... } @Override public void play() { .... }
26th Apr 2021, 4:57 AM
sarada lakshmi
sarada lakshmi - avatar
0
interface methods are public, so do all implemented and abstract methods public and no protected
26th Apr 2021, 7:33 AM
zemiak
0
thank you
2nd May 2021, 3:35 AM
lordzrealm
lordzrealm - avatar