איזה קומפיילר? אממ לא יודע...../images/Emo122.gif
לפרסם איזה קוד? של המחלקות? כי הבעיה היא רק בTest! הנה הן בכל מקרה:
public class Animal { protected String name; protected int age; protected int numOfLegs; protected int energy; public Animal(String name, int age, int numOfLegs, int energy) { this.name=name; this.age=age; this.numOfLegs=numOfLegs; this.energy=energy; } public Animal() { this.name="Ish"; this.age=0; this.numOfLegs=2; this.energy=100; } public void setName(String name){ this.name=name; } public void setAge(int age){ this.age=age; } public String getName(){ return this.name; } public int getAge(){ return this.age; } public int getNumOfLegs(){ return this.numOfLegs; } public void eat(int amount){ this.energy+=amount; } public void exercise(int amount){ if (amount>this.energy) System.out.print("You wanna kill him?!"); else this.energy-=amount; } public void talk() { System.out.println("Bla."); } public String details() { return ("Name: "+this.name+", Age: "+this.age+", Legs: "+this.numOfLegs+", Energy: "+this.energy); } } public class Mammal extends Animal { protected int milk; public Mammal(String name, int age, int numOfLegs, int energy, int milk){ super(name, age, numOfLegs, energy); this.milk=milk; } public Mammal() { super(); this.milk=0; } public void drinkMilk(int amount) { this.milk+=amount; } public void giveMilk(int amount) { if (amount>this.milk) System.out.print("Not enough milk!"); else this.milk-=amount; } public int getMilk() { return this.milk; } public void talk() { System.out.println("Prrr!"); } public String details() { return ("Name: "+this.name+", Age: "+this.age+", Legs: "+this.numOfLegs+", Energy: "+this.energy+", Milk: "+this.milk); } } public class Dog extends Mammal { protected String breed; public Dog(String name, int age, int energy, int milk, String breed) { super(name, age, 4, energy, milk); this.breed=breed; } public Dog() { super(); this.breed="Mutt"; } public String getBreed() { return this.breed; } public void talk() { System.out.println("Wuff!"); } public String details() { return ("Name: "+this.name+", Age: "+this.age+", Legs: "+this.numOfLegs+", Energy: "+this.energy+", Milk: "+this.milk+", Breed: "+this.breed); } }
מישהו מוצא את הבעיה