mike109
Messages postés7Date d'inscriptionmercredi 23 février 2005StatutMembreDernière intervention15 janvier 2008
-
1 mai 2005 à 21:10
cs_neodante
Messages postés2835Date d'inscriptionlundi 11 août 2003StatutModérateurDernière intervention16 décembre 2006
-
2 mai 2005 à 10:32
Bonjour,
Je cherche à tester ça (oui je sais c'est tout con lol)
//Tous les animaux doivent implémenter les méthodes suivantes
//On remarque qu'une interface ne possède pas de constructeur ...
public interface Animal {
void manger(String nourriture);
void seDeplacer();
void respirer();
}
//Une interface plus spécifique
public interface Parler {
void parle(String phrase);
}
//Une interface plus spécifique
public interface Aboyer {
void aboie();
}
class Homme implements Animal, Parler {
//Implémentation de l'interface Animal
public void manger(String nourriture) {
System.out.println("Nourriture : " + nourriture);
}
public void seDeplacer() {
System.out.println("Déplacement du chien");
}
public void respirer() {
System.out.println("Respiration du chien");
}
//Implémentation de l'interface Aboyer
public void parle(){
System.out.println("Ouaf !");
}
}
class Homme implements Animal, Parler {
//Implémentation de l'interface Animal
public void manger(String nourriture) {
System.out.println("Nourriture : " + nourriture);
}
public void seDeplacer() {
System.out.println("Déplacement du chien");
}
public void respirer() {
System.out.println("Respiration du chien");
}
//Implémentation de l'interface Aboyer
public void parle(){
System.out.println("Ouaf !");
}
}
public class Main {
public Main() {
}
public static void main(String[] args) {
Chien monAnimal=new Chien();
Homme moi=new Homme();
moi.seDeplacer();
moi.parle("J'ai faim");
moi.manger("Frite");
moi.respirer();
monAnimal.manger("Cesar");
monAnimal.aboie();
monAnimal.seDeplacer();
}
}
Bien sûr, j'ai mis ça dans des fichiers différents mais il me plante à la compil :
Compiling 3 source files to C:\Info\2emeAnnee\LaboPOO\JAVA\Interface_Ex\build\classes
C:\Info\2emeAnnee\LaboPOO\JAVA\Interface_Ex\src\interface_ex\Chien.java:3:
interface_ex.Chien is not abstract and does not override abstract
method aboie() in interface_ex.Aboyer
class Chien implements Animal, Aboyer{
C:\Info\2emeAnnee\LaboPOO\JAVA\Interface_Ex\src\interface_ex\Homme.java:3:
interface_ex.Homme is not abstract and does not override abstract
method parle(java.lang.String) in interface_ex.Parler