Eh bien c'est une pure question d'objet!
En fait si j'ai compris ta une classe A :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public class Toto {
private String champ1;
private String champ2;
private String champ3;
public Toto(String champ1, String champ2, String champ3) {
// TODO Auto-generated constructor stub
this.champ1 = champ1;
this.champ2 = champ2;
this.champ3 = champ3;
}
public Toto()
{
this.champ1 = "";
this.champ2 = "";
this.champ3 = "";
}
public String getChamp1() {
return champ1;
}
public void setChamp1(String champ1) {
this.champ1 = champ1;
}
public String getChamp2() {
return champ2;
}
public void setChamp2(String champ2) {
this.champ2 = champ2;
}
public String getChamp3() {
return champ3;
}
public void setChamp3(String champ3) {
this.champ3 = champ3;
}
} |
Pour avoir accès a ta classe A depuis ta class B il faut que tu instancie ta classe A cad que tu dois créer un objet de type A comme tu fais pour créer un int (int toto = new Integer()
et bien la tu va faire
Toto maClasseA = new Toto();
ensuite tu auras donc accès a tous les champs privé de a.Donc à tes getters.
Voici le code
1 2 3 4 5 6 7 8 9 10 11
| public class B {
public B()
{
//on crée un objet de type Toto =on crée une instance de toto
toto monToto = new toto();
//on a accès a tous les champs privés de Toto
monToto.getChamp1();
}
} |
Partager