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(); }}
7 Answers
+ 2
I have tested your code, nothing wrong here.
+ 1
As I said, nothing wrong here. What's your error?
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();
}
}
0
i think it shld jst work f9
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();
}
}
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();
}
}
0
I don't know about that. The code seems okay!