
4TABLE DES MATI `
ERES
4 Fondements objet de Java 29
4.1 Structure des classes en Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.1.1 Syntaxe d’une classe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.1.2 Modes d’encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.1.3 D´er´ef´erencement des attributs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.1.4 Attributs final . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.1.5 Attributs static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.1.6 Constructeurs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
4.1.7 Notes sur les constructeurs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Constructeurs, accesseurs et mutateurs final . . . . . . . . . . . . . . . . . . . 32
Utilisation de this() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.1.8 Le destructeur finalize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.1.9 Conversion des objets en chaˆıne de caract`eres . . . . . . . . . . . . . . . . . . . 33
4.2 Classes enveloppantes des types primitifs . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.3 Classes internes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5 H´eritage, classes abstraites et interfaces 35
5.1 H´eritage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.1.2 Les classes Object et Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.2 M´ethodes et classes abstraites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5.3 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.3.2 H´eritage multiple des interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.3.3 Impl´ementation d’une interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.3.4 Interfaces indicatrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6 Interruptions 41
6.1 La classe Throwable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.2 Syntaxe des gestionnaires d’interruptions . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.3 La classe Exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.4 La classe Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
6.5 Interruptions v´erifi´ees et non-v´erifi´ees, RuntimeException . . . . . . . . . . . . . . . . 44
7 Paquetages et documentation 47
7.1 Paquetages (package) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
7.2 Javadoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7.2.1 G´en´eration automatique de documentation . . . . . . . . . . . . . . . . . . . . 48
7.2.2 D´efinition de quelques balises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
8´
Egalit´e, comparabilit´e, clonage 51
8.1 Transtypage (cast) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8.1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8.1.2 L’op´erateur instanceof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
8.1.3 Upcast implicite des types primitifs . . . . . . . . . . . . . . . . . . . . . . . . 52
8.1.4 Downcast explicite des types primitifs . . . . . . . . . . . . . . . . . . . . . . . 53
8.1.5 Upcast implicite des types non-primitifs . . . . . . . . . . . . . . . . . . . . . . 53
8.1.6 Downcast explicite des types non-primitifs . . . . . . . . . . . . . . . . . . . . . 53
8.1.7 Tableaux de types non-primitifs . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
8.2 ´
Egalit´e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
8.3 Comparabilit´e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
8.4 Copie et clonage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55