You are on page 1of 3

Exercice 1 [ 6 pts]

1)
a. Le programme affiche
Test: POO, Java 8 2
Test: POO, 8 2
8
3
b. Le programme affiche
Test: POO, Java 8 1
Test: POO, 8 2
8
3
2)
a. Le programme affiche
POO SMI
POO SMI
POO SMI
Info5 SMA
Info5 SMA
Info5 SMA
4 -1 2
b. Le programme n'est pas compil parce que un programme Java est constitu dune
ou de plusieurs classes. Mais ne peut contenir quune seule classe publique
contenant la mthode main().

Exercice 2 [ 9 pts]
class Personn {
private String nom;
private int age;
public Personn(String nom, int age)
{
this.nom=nom;
this.age = age;
}

1/3
public Personn(){
this("Elhadi", 20);
}

public Personn(Personn p) {
nom = p.nom;
age = p.age;
}

public String getNom(){return nom;}

public int getAge(){return age;}

public boolean egalite(Personn p)


{
if (nom.equals(p.nom) && (age == p.age))
return true;
else return false;
// ou bien return (nom.equals(p.nom) && (age == p.age));
}
public void afficher() {
System.out.println("Nom : " + nom);
System.out.println("Age : " + age + " ans ");
}
public void afficher(boolean compact)
{
if (compact == false)
afficher();
else
System.out.println("[" + nom + ", " + age + "]");
}
}
////////////////////////////////////////////////////////////////////
class Etudian extends Personn{
private String fil;
Etudian(String nom, int age, String fil)
{
super(nom, age);
this.fil = fil;
}
public Etudian(Personn p, String fil)
{
super(p);
this.fil = fil;
}
public static boolean egalite(Etudian e1,Etudian e2)
{
return (e1.getNom().equals(e2.getNom()) && e1. getAge() == e2. getAge()
&& e1.fil.equals(e2.fil));
}

2/3
public void afficher() {
System.out.println("Je suis un Etudiant(e)\n");
super.afficher();
System.out.println("Ma filire est:"+ fil);
}
}
////////////////////////////////////////////////////
public class TestPersEtud{
public static void main(String[] args) {
Personn p1 = new Personn("Elhadi ",20);
p1.afficher();
Personn p2 = new Personn();
p2.afficher();
Personn p3 = new Personn(p2);
p3.afficher(true);
boolean bool1=p1.egalite(p2);
System.out.println("Mme Personne:"+bool1);
///////////////////////////
Etudian e1 = new Etudian(p1,"SMI5");
e1.afficher();
Etudian e2 = new Etudian("hachimi", 20,"SMI5");
e2.afficher();
boolean bool2=Etudian.egalite(e1,e2);
System.out.println("Mme Etudiant:"+bool2);
}
}

Exercice 3 [ 5 pts] : Voir le cours

3/3

You might also like