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