-
-
Save mikamboo/5684516 to your computer and use it in GitHub Desktop.
Java create a class : constructors & get / set methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Classe Personne | |
* Décrit un objet personne par son nom et son age | |
* | |
*/ | |
public class Personne { | |
private String name; | |
private int age; | |
/* | |
* Dans ce constructeur on initialise seulement le nom | |
*/ | |
public Personne(String nom_personne){ | |
name = nom_personne; | |
} | |
/* | |
* Dans ce constructeur on initialise nom et age | |
*/ | |
public Personne(String nom_personne, int age_personne){ | |
name = nom_personne; | |
age = age_personne; | |
} | |
public String getName(){ | |
return name; | |
} | |
public void setName(String name){ | |
this.name = name; | |
} | |
public int getAge(){ | |
return age; | |
} | |
public void setName(int age){ | |
this.age = age; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment