I'm trying to add three kinds of monsters into an array by initializing my Monster-object based on the modulo. (I'm just a beginner so bare with me).
for (int i=0; i<nrofMonsters; i++) {
Monster m;
if (i%2==0) {
m = new Vampire("Vamp-"+i);
} else if(i%2==1) {
m = new Ghost("Ghost-"+i);
} else if(i%3==2){
m = new Demon("Demon-"+i);
}
monsters.add(m);
}
ERROR MESSAGE: variable m might not have been initialized.
Aucun commentaire:
Enregistrer un commentaire