erreur: non-static variable
Bonjour,
Je débute en java et j'ai les erreurs suivantes:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| Batiment.java:103: non-static variable numero cannot be referenced from a static context
System.out.println("Fermeture du batiment "+numero+" en cours...");
^
Batiment.java:104: non-static variable nbureau cannot be referenced from a static context
for(j=0;j<nbureau.length;j++)
^
Batiment.java:106: non-static variable nbureau cannot be referenced from a static context
buro=nbureau[j];
^
Batiment.java:109: non-static variable numero cannot be referenced from a static context
System.out.println("Tous les bureaux du batiment "+numero+" sont fermes");
^
4 errors |
le code:
Code:
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| class Batiment
{
int numero; // numero du batiment
Bureau nbureau[]; // tableau de tous les bureaux du batiment
Batiment(int num_bat,int n)
{
numero=num_bat;
nbureau=new Bureau[n];
for(int i=0;i<n;i++)
nbureau[i]=new Bureau(i+1);
}
static void metAlarme(boolean b)
{
int i,j;
boolean alarme=false;
Bureau buro;
alarme=b;
if(!alarme)
System.out.println("L'alarme est desactive");
else
{
System.out.println("L'alarme est active");
System.out.println("");
System.out.println("Fermeture du batiment "+numero+" en cours...");
for(j=0;j<nbureau.length;j++)
{
buro=nbureau[j];
buro.fermer();
}
System.out.println("Tous les bureaux du batiment "+numero+" sont fermes");
System.out.println("");
}
}
public static void main(String[]args)
{
Batiment bat1=new Batiment(1,3);
Batiment bat2=new Batiment(2,4);
Employe empl=new Employe(bat1,3);
bat1.metAlarme(true);
bat2.metAlarme(true);
empl.aller(bat2,2);
}
} |
Je ne comprend pas ces erreurs. que faut il que je fasse ?