0
Why does this give error?
Why does this give error and Cat is not an abstract class? it's a code written in java tutorial and the method was void. I just changed it to String to have return a value.but it doesn't work.why? What's the problem? the method must be only void type? abstract class Animal { int legs = 0; abstract String makeSound(); } class Cat extends Animal { public String makeSound(String a) { String b = a + " world"; return b; } } public class Program { public static void main(String[] args) { Cat c = new Cat(); System.out.println(c.makeSound("Hello")); } } https://code.sololearn.com/c7p8JWPLEXDO/?ref=app
3 Réponses
+ 4
In abstract class method makeSound don't take any parameter but class Cat has parameter.
In general, you didn't override method from abstract class in cat class.
+ 4
salar vhd no problem, good luck 😄
+ 2
Yeaaaah That's right. I thought we can't include any parameter in abstract method in abstract class. Thank you :))