public class Petcount3 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Vector pets=new Vector();
Class[]petTypes={
pet.class,
Dog.class,
Pug.class,
Cat.class,
Rodent.class,
Gerbil.class,
Hamster.class,
};
try{
for(int i=0;i<15;i++){
int rnd=1+(int)(Math.random()*(petTypes.length-1));
pets.addElement(petTypes[rnd].newInstance());
}
}
catch(InstantationException e){
}
有谁能帮我解释一下for里面的东东?谢谢!
|