0

Why this will be wrong if i will add this

Cat d = new Cat ();d.makeSound(); in the below program:-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"); }}public class Program { public static void main(String[] args) { Cat c = new Cat(); c.eat(); }}

12th Sep 2016, 7:04 PM
Abhishek Kumar
Abhishek Kumar - avatar
7 Answers
+ 2
I have tested your code, nothing wrong here.
12th Sep 2016, 7:39 PM
Zen
Zen - avatar
+ 1
As I said, nothing wrong here. What's your error?
12th Sep 2016, 8:09 PM
Zen
Zen - avatar
0
@Zen actually i am trying to print Meow and omnomnom both together. But when i am running this program, it shows error : 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"); } } public class Program { public static void main(String[] args) { Cat c = new Cat(); c.eat(); Cat d = new Cat(); d.makeSound(); } }
12th Sep 2016, 7:57 PM
Abhishek Kumar
Abhishek Kumar - avatar
0
i think it shld jst work f9
12th Sep 2016, 10:15 PM
Bhushan Gaikwad
Bhushan Gaikwad - avatar
0
@aone 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"); } } public class Program { public static void main(String[] args) { Cat c = new Cat(); c.eat(); Cat d = new Cat(); d.makeSound(); } }
13th Sep 2016, 2:24 AM
jao
jao - avatar
0
@aone 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"); } } public class Program { public static void main(String[] args) { Cat c = new Cat(); c.eat(); Cat d = new Cat(); d.makeSound(); } }
13th Sep 2016, 2:24 AM
jao
jao - avatar
0
I don't know about that. The code seems okay!
13th Sep 2016, 8:33 AM
Sam Sung
Sam Sung - avatar