Bonjour à tous,

J'ai une erreur avec ce code alors que j'essaie de définir simplement un accesseur dans une classe ...

L'erreur est la suivante :

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token "getNbreHabitants", AnnotationName expected after this token
Illegal modifier for parameter getNbreHabitants; only final is permitted
Syntax error, insert "[ ]" to complete Dimension
Syntax error, insert ";" to complete LocalVariableDeclarationStatement
Void methods cannot return a value

at essai5.Ville.<init>(Ville.java:25)
at essai5.essai5.main(essai5.java:7)


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
package essai5;
 
public class essai5 {
 
	public static void main (String[] args) {
		System.out.println("Hello World");
		Ville ville=new Ville("Marseille", 1000000, "France");
		}
 
}

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
package essai5;
 
public class Ville { 
private static final String String = null;
private String nomVille;
private String nomPays;
private int nbreHabitants;
 
public Ville() {
	System.out.println("Création d'une ville !");
	nomVille="Inconnu";
	nomPays="Inconnu";
	nbreHabitants=0;
	}
 
public Ville(String pNom, int pNbre, String pPays) {
	System.out.println("Création d'une ville Marseille !");
	nomVille=pNom;
	nomPays=pPays;
	nbreHabitants=pNbre;
 
 
	//********** ACCESSEURS ************
 
	public int getNbreHabitants() 
	{
	return nbreHabitants;
	}
 
 
 
}
 
 
}
D'avance, merci.