Probleme attribut

Résolu/Fermé
helloworld95 - 9 oct. 2018 à 18:28
 helloworld95 - 9 oct. 2018 à 18:32
Bonjour,

J'ai une classe Client avec un attribut commande. Le problème est que le résultat de getNumero() est 0 alors qu'il devrait etre 2.


public class Client {
	
	private String nom, prenom;
	private Commande commande;

	public Client(String prenom, String nom) {
		this.prenom = prenom;
		this.nom = nom;
	}
	
	public void enregistrerCommande(Commande commande) {
		this.commande = commande;
	}
	
	public Commande getCommande() {
		return this.commande;
	}


public class Test {
	public static void main(String[] args) {
		Client client = new Client("Robert", "Michel");
		Commande commande = new Commande(2, LocalDateTime.now());
		client.enregistrerCommande(commande);
		System.out.println(client.getCommande().getNumero());
	}




2 réponses

KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
9 oct. 2018 à 18:31
Bonjour,

Comment est fait la classe Commande ? En particulier le constructeur et la méthode getNumero.
0
helloworld95
9 oct. 2018 à 18:32
C'est bon j'ai trouvé par moi même
0