Package com. softeem. Demo;
/**
* @ Authorleno
* Animal Interfaces
*/
Interface animal
{
Publicvoid eat (Food food );
}
/**
* @ Authorleno
* Animal: Cat
*/
Class cat implements animal
{
Publicvoid eat (Food food)
{
System. Out. println ("kitten" + food. getname ());
}
}
/**
* @ Authorleno
* Animal: Dog
*/
Class dog implements animal
{
Publicvoid eat (Food food)
{
System. Out. println ("Puppy chew" + food. getname ());
}
}
/**
* @ Authorleno
* Abstract Food class
*/
Abstractclass food
{
Protected string name;
Public String getname (){
Returnname;
}
Publicvoid setname (string name ){
This. Name = Name;
}
}
/**
* @ Authorleno
* A type of food: Fish
*/
Class fish extends food
{
Public fish (string name ){
This. Name = Name;
}
}
/**
* @ Authorleno
* A type of food: Bone
*/
Class bone extends food
{
Public bone (string name ){
This. Name = Name;
}
}
/**
* @ Authorleno
* Breeders
*
*/
Class Feeder
{
/**
* The breeder feeds some food to an animal.
* @ Paramanimal
* @ Paramfood
*/
Publicvoid feed (animal, Food food)
{
Animal. Eat (food );
}
}
/**
* @ Authorleno
* Test whether a breeder feeds animals.
*/
Publicclass testfeeder {
Publicstaticvoid main (string [] ARGs ){
Feeder feeder = new feeder ();
Animal animal = new dog ();
Food food = new bone ("meat bone ");
Feeder. Feed (animal, food); // feed the meat to the dog
Animal = new CAT ();
Food = new fish ("fish ");
Feeder. Feed (animal, food); // feed the cat
}
}