Affichage 2 livre en java
Résolu
touta_touta
Messages postés
337
Date d'inscription
Statut
Membre
Dernière intervention
-
touta_touta Messages postés 337 Date d'inscription Statut Membre Dernière intervention -
touta_touta Messages postés 337 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
je veux afficher 2 livre mais le programme n'affiche rien et ça le programme
public class livre
{
//variables
public String titre ,auteur;
public int nbpages;
String l1;
String l2;
//constructeur
public livre(String unAuteur,String unTitre)
{
auteur=unAuteur;
titre=unTitre;
}
//accesseur
public String getAuteur()
{
return auteur;
}
//modificateur
void setnbpages(int n)
{
nbpages=n;
}
public static void main(String[] args)
{
livre l1=new livre("shekspeere","les bourgois");
livre l2=new livre("taha hsin","al ayem");
}
public void affiche()
{
System.out.println(l1);
System.out.println(l2);
}
}
je veux afficher 2 livre mais le programme n'affiche rien et ça le programme
public class livre
{
//variables
public String titre ,auteur;
public int nbpages;
String l1;
String l2;
//constructeur
public livre(String unAuteur,String unTitre)
{
auteur=unAuteur;
titre=unTitre;
}
//accesseur
public String getAuteur()
{
return auteur;
}
//modificateur
void setnbpages(int n)
{
nbpages=n;
}
public static void main(String[] args)
{
livre l1=new livre("shekspeere","les bourgois");
livre l2=new livre("taha hsin","al ayem");
}
public void affiche()
{
System.out.println(l1);
System.out.println(l2);
}
}
A voir également:
- Affichage 2 livre en java
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Supercopier 2 - Télécharger - Gestion de fichiers
- Eclipse java - Télécharger - Langages
- Java apk - Télécharger - Langages
1 réponse
Tu dois mettre le contenu de la méthode "affiche" dans ton main :
Mais pour que cela affiche correctement tes données, tu devras redéfinir la méthode
public static void main(String[] args) { livre l1=new livre("shekspeere","les bourgois"); livre l2=new livre("taha hsin","al ayem"); System.out.println(l1); System.out.println(l2); }
Mais pour que cela affiche correctement tes données, tu devras redéfinir la méthode
public String toString()qui est appellée implicitement par la méthode
println.
livre@2bd9c3e7
Normal, tu n'as pas redéfini la méthode toString...