7. public class Employee { public class Manager {
String name; String name;
Date hireDate; Date hireDate;
Date dateOfBirth; Date dateOfBirth;
String jobTitle; String jobTitle;
int grade; int grade;
} String department;
Employee [] subordinates;
}
7
11. public class Manager
public class Employee extends Employee {
{ String department;
String name; Employee []
Date hireDate; subordinates;
Date dateOfBirth; }
String jobTitle;
int grade;
}
11
31. public class Manager
public class Employee extends Employee {
{ String department;
String name; Employee []
Date hireDate; subordinates;
Date dateOfBirth; }
String jobTitle;
int grade;
}
31
32. class Societe public void affichePrime(){
{ for (int i=0;i<compteur;i++){
Employe [] tabEmpl; System.out.println
int compteur=0; (tabEmpl[i].calculPrime());
Societe(int taille)
}
{
tabEmpl = new Employe[taille]; }
} public static void main(String []
public void recuter(Employe e){ args){
tabEmpl[compteur]=e; Societe s = new Societe();
compteur++; s.recruter(new Employe());
} s.recruter(new Manager());
s.affichePrime();
}
}
32
36. ï± Returns a string representation of the object. In general,
the toString method returns a string that "textually
represents" this object. The result should be a concise but
informative representation that is easy for a person to read.
It is recommended that all subclasses override this method.
The toString method for class Object returns a string
consisting of the name of the class of which the object is an
instance, the at-sign character `@', and the unsigned
hexadecimal representation of the hash code of the object.
In other words, this method returns a string equal to the
value of:
ï± getClass().getName() + '@' +
Integer.toHexString(hashCode())
ï± Returns:
ïź a string representation of the object.
36
37. public class Personne {
String nom,prenom;
public static void main(String
args[]){
Personne p = new Personne();
System.out.println(p);
}
}
37
39. public class Personne {
String nom,prenom;
public static void main(String
args[]){
Personne p = new Personne();
//System.out.println(p);
System.out.println(p.toString());
}
}
39
41. public class Personne extends Object{
String nom,prenom;
public String toString(){return « nom=«
+nom+ « prenom=»+prenom;}
public static void main(String args[]){
Personne p = new Personne();
p.nom=«a »,p.prenom=« b »;
System.out.println(p);
//System.out.println(p.toString());
}
}
41
55. ïź Appel d'un constructeur de la mĂȘme classe :
public MaClasse(int a, int b) {
...
}
public MaClasse(int c) {
this(c, 0);
}
public MaClasse() {
this(10);
}
55
56. public class Personne {
String nom,prenom;
Public void affiche(){
System.out.println(this);
//System.out.println(this.toString());
//System.out.println(toString());
}
public String toString(){return « nom=« +nom+ «
prenom=»+prenom;}
public static void main(String args[]){
Personne p = new Personne();
//System.out.println(p);
System.out.println(p.toString());
}
}
56
58. Premier cas :
class ClientRegulier extends Client {
double ristourne;
public String toString() {
return super.toString() + "ristourne=" +
ristourne;
. . .
}
}
class Client {
String nom ;
String clientID ;
public String toString() {
return "nom=" + nom + " id=" + clientID;
}
}
58
59. ïź DeuxiĂšme cas :
ïź Appel d'un constructeur de classe de base :
class ClientRegulier extends Client {
ClientRegulier( String leNom, String id,double ris) {
super ( leNom, id);
...
}
}
59
62. public class personne{ // accesseurs
private String prenom; public String getPrenom(){
private String nom; return prenom;
private int age; }
public personne(String P, String public String getNom(){
N, int age){
return nom;
this.prenom=P;
}
this.nom=N;
public int getAge(){
this.age=age;
return age;
}
}
public personne(personne P){
//modifieurs
this.prenom=P.prenom;
public void setPrenom(String P){
this.nom=P.nom;
this.prenom=P;
this.age=P.age;
}
}
public void setNom(String N){
public String identite(){
this.nom=N;
return
"personne("+prenom+","+nom+", }
"+age+")"; public void setAge(int age){
} this.age=age;
}
}
62
63. class enseignant extends personne{
// attributs
private int section;
// constructeur
public enseignant(String P, String N, int
age,int section){
super(P,N,age);
this.section=section;
}
}
63
68. Exemple :
// dans java.lang.Math
public static final double PI =
3.14159265358979323846;
// dans java.awt.Color
public static final Color white
= new Color(255, 255, 255);
// dans un champ d'instance
private final Date
dateCreationInstance = new Date();
68
69. ïź // java 1.1 "final" comme contrĂŽle d'initialisation
unique
public class Client {
public final String clientID;
...
public Client( String nom, String ID) {
clientID = ID ;
....
}
}
69
83. ïź Une variable statique est une variable unique
accessible via une instance quelconque de la
classe.
ïź Le plus souvent on y accĂšde Ă lâaide du nom
de la classe
83
84. public class StaticVar {
public static int number;
}
public class OtherClass {
public void method() {
int x = StaticVar.number;
}
}
84
86. public class GeneralFunction {
public static int addUp( int x, int y) {
return x + y;
}
}
public class UseGeneral {
public void method() {
int a = 9;
int b = 10;
int c = GeneralFunction.addUp(a , b);
System.out.println("addUp() gives" + c);
}
}
86
93. public class Employee {
String name;
Date hireDate;
Date dateOfBirth;
String jobTitle;
int grade;
}
public class Manager extends Employee {
String department;
Employee [] subordinates;
}
93