Version without JavaScript, read-only: workshops, quizzes and running code are not available here. Full version · Catalogue · Sign in

Sequence

Inheritance: the Etudiant class

Core exercise

In Etudiant.java, create a class Etudiant (student) that inherits from Personne and adds an attribute numEtudiant (a String, the student number), with its getter getNumEtudiant(). The constructor takes the four values.

A workshop goes here: you write and run code in it. It requires JavaScript.

Starting code

Personne.java

public class Personne {

    private String nom;
    private String prenom;
    private int age;

    public Personne(String nom, String prenom, int age) {
        this.nom = nom;
        this.prenom = prenom;
        this.age = age;
    }

    public String getNom() {
        return nom;
    }

    public String getPrenom() {
        return prenom;
    }

    public int getAge() {
        return age;
    }

    public void afficherDetails() {
        System.out.println(prenom + " " + nom + ", " + age + " ans");
    }
}

Etudiant.java

// TODO : Etudiant herite de Personne
public class Etudiant {

    // TODO : l'attribut numEtudiant

    // TODO : le constructeur (nom, prenom, age, numEtudiant) avec super(...)

    // TODO : getNumEtudiant()
}

Exercices.java

public class Exercices {

    public static void main(String[] args) {
        // Une fois Etudiant.java ecrite, remplacez ces lignes par :
        //     Etudiant e = new Etudiant("Dupont", "Jean", 18, "3iL2025");
        //     e.afficherDetails();
        //     System.out.println("numero : " + e.getNumEtudiant());
        System.out.println("Completez Etudiant.java, puis lancez Verifier.");
    }
}

The core exercise is validated in the workshop, which requires JavaScript.

Hint 1

The constructor of the child class calls that of the parent with super(nom, prenom, age), and this call must be the first instruction of the constructor. An Etudiant is a Personne: all its public methods remain available.