public boolean equals(Object o){
public boolean equals(Object o){
Point tmp = (Point)o;
return((this.x==tmp.x)&&(this.y==tmp.y));
}
p.equals(p2)
Point tmp = (Point)o;
Publicité
return((this.x==tmp.x)&&(this.y==tmp.y));
}
public String toString() {
return "The point x=" + x + ", y=" + y ;
}
public PointCol(int a, int b, String uneCouleur) {
super(a,b); //C’est obligatoire sinon 🡪 appel automatique à super()
Publicité
couleur = uneCouleur;
}
System.out.println(p.toString());
Ou :
System.out.println(lesComptes[0]);
// Création ET initialisation d'un tableau d'objets :
Etudiant[] tab = { new Etudiant("A", "B", 25, 12),
Publicité
new Etudiant("C", "D", 21, 17),
new Etudiant("E", "F", 27, 16),
new Etudiant("G", "H", 24, 13) };
// ou encore :
CompteBancaire[] lesComptes = new CompteBancaire[10]; //ou sans « 10 »
lesComptes[0]=cc1;
lesComptes[1]=ce1;
Publicité
rques :
- On a créeé un tableau de comptes bancaires mais si on appelle n’importe quelle fct (ici : retirerArgent() et toString() ) il cherche le vrai type de l’objet