why i could not create new dog class and object like as cat class ? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

why i could not create new dog class and object like as cat class ?

interface Animal { public void eat(); public void makeSound(); } class Cat implements Animal { public void makeSound() { System.out.println("Meow"); } public void eat() { System.out.println("omnomnom"); } } class Dog implements Animal { public void makeSound() { System.out.println("brow"); } } public class Program { public static void main(String[] args) { Cat c = new Cat(); c.eat(); Dog d = new Dog(); d.makeSound(); } } /* output is ; ..\Playground\:4: error: Dog is not abstract and does not override abstract method eat() in Animal class Dog implements Animal { ^ 1 error */

26th Jan 2017, 6:31 PM
Feridun Subasi
Feridun Subasi - avatar
1 Antwort
+ 2
When you implement an interface, you have to override all of its methods (eat is missing). As long, as you don't create an abstract class.
26th Jan 2017, 6:38 PM
Heroes Killer
Heroes Killer - avatar