Méthode super() avec paramètres
Bonjour,
J'ai un problème lors de l'utilisation d'une méthode super lorsque je dois passer des paramètres. Voici mon exemple :
Classe mère :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package heritage2;
public class Animal {
protected String nom;
protected int age;
protected double prix;
public Animal (String nom, int age, double prix){
this.nom=nom;
if ((age<0)||(prix<0)){
throw new IllegalArgumentException ("Prix et age doivent être positif !");
}
else {
this.age=age;
this.prix=prix;
}
}
public String getNom(){return nom;}
public int getAge(){return age;}
public double getPrix(){return prix;}
public void setNom (String nom){this.nom=nom;}
public void setAge(int age) {this.age=age;}
public void setPrix(double prix){this.prix=prix;}
public String toString(){
return "Cet animal s'appelle : "+nom+", il a "+age+" ans et coute "+prix+" euros.";
}
} |
Classe fille :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
package heritage2;
public class Espèces extends Animal{
protected String espèce;
public Espèces(String espèce){
super(???);
this.espèce = espèce;
}
} |
Je comprend lorsqu'il n'y a pas de paramètres au constructeur, mais dès qu'il y en a, plus moyen ...
D'avance, merci.