This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Could someone explain what is the error in this program? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Could someone explain what is the error in this program?" Watch "Could someone explain what is the error in this program?" New topic

Could someone explain what is the error in this program?

bobby Varghese

Joined: Feb 12, 2009
Posts: 6
public class Animal extends SimpleElement
public final static int MAMMAL = 1;
int animalClass;
String name, species, habitat, food, temperament;
FoodRecipe foodRecipe;
public void setName( String name )
{ = name;
public String getName()
return name;
public void setSpecies( String species )
this.species = species ;
public String getSpecies()
{ return species;
public void setHabitat( String habitat )
this.habitat = habitat ;
public String getHabitat()
return habitat;
public void setFood( String food )
{ = food ;
public String getFood()
return food;
public void setFoodRecipe( FoodRecipe recipe )
this.foodRecipe = recipe;
public FoodRecipe getFoodRecipe()
return foodRecipe;
public void setTemperament( String temperament )
this.temperament = temperament ;
public String getTemperament()
return temperament;
public void setAnimalClass( int animalClass )
this.animalClass = animalClass;
public int getAnimalClass()
return animalClass;
public void setAttributeValue( String name, String value )
if ( name.equals("class") && value.equals("mammal") )
setAnimalClass( MAMMAL );
throw new Error("No such attribute: "+name);
public String toString()
return name +"("+species+")";
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2904

Have you complied this program? What compiler says? What's the error, If you post the error, then its easy for Ranchers to explain the cause of error . And Please use Code Tags

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

Other than the fact that the classes SimpleElement and FoodRecipe aren't defined here (and they'd need to be for this code to compile) I don't see any outright errors.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Could someone explain what is the error in this program?
It's not a secret anymore!