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 38 39 40 41 42 43
| class Test{
// variable d'instance
private StringBuffer strB = new StringBuffer();
// méthode d'instance 'abc'
public void abc(){
strB.append("a");
strB.append("b");
strB.append("c");
}
// méthode d'instance 'getteur'
public StringBuffer getStrB(){
return strb;
}
// méthode d'instance 'initialisation'
public initStrB(){
strB.delete( 0,strB.length() )
}
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class Main{
public static void main(String[] args){
Test monObjet = new Test();
//... une suite d'instructions... par xemple
monObjet.abc();
// initialisation de monObjet.strB (Méthode 1)
monObjet.getStrB().delete( 0,monObjet.getStrB().length() )
// ou bien (Méthode 2)
monObjet.initStrB();
}
} |