如何在数组列表中收集抽象类创建的所有ο对象



如何在数组列表中收集抽象类创建的所有ο对象?

这是我到目前为止所尝试的:

package exercice3;
import java.util.ArrayList;
import java.util.List;
public abstract class Personne {

protected String nom ;
protected String prenom ; 
protected String adresse ;
protected static int nbPersonnes = 0 ; 
List<Personne> ListePersonnes = new ArrayList <>();

public Personne(String nom , String prenom , String adresse) {

this.nom= nom ; 
this.prenom = prenom ; 
this.adresse = adresse ; 
nbPersonnes++;
ListePersonnes.add(nbPersonnes, );
}
}
public abstract class Personne {

protected String nom ;
protected String prenom ; 
protected String adresse ;
protected static int nbPersonnes = 0 ; 
static List<Personne> ListePersonnes = new ArrayList<>();



public Personne(String nom , String prenom , String adresse) {

this.nom= nom ; 
this.prenom = prenom ; 
this.adresse = adresse ; 
nbPersonnes++;
ListePersonnes.add(this);  // <== use 'this' keyword

}
}

最新更新