English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

created an interface called rodents :
interface Rodents
{
public void eat();
}
i ve created another class which implement this rodent interface:
class Mouse implements Rodents
{
public void eat()
{
System.out.println("I eat fast");
}
}
class Gerbil implements Rodents
{
public void eat()
{
System.out.println("I eat at an average rate");
}
}
class Hamster implements Rodents
{
public void eat()
{
System.out.println("I eat at an average rate");
}
}

class RodentTest
{
public static void main(String args[])
{
Mouse m=new Mouse();
Gerbil g=new Gerbil();
Hamster h=new Hamster();
Rodents rodents;
rodents=m;
System.out.println(m.eat());
rodents=g;
System.out.println(g.eat());
rodents=h;
System.out.println(h.eat());
}
}

i get an error like this when i compile the above program:
void type not allowed here System.out.println(m.eat()).
Similar error for g.eat() and h.eat().
Where have i gone wrong? Could any1 help me.
Thanks in advance

2007-07-03 12:30:56 · 1 answers · asked by Anonymous in Computers & Internet Programming & Design

1 answers

I'm a little rusty at C but your calling a function called eat() is returning a Void. So you are trying to print a void (nothing). (Hence the void type not allowed error)
Also I see multiple functions called eat being defined, shouldn't these have different names ?

2007-07-03 13:37:57 · answer #1 · answered by MarkG 7 · 0 0

fedest.com, questions and answers