Saturday, November 30, 2013

Creating a 2D object array in a loop








I have an object with two constants that I want initialising in the constructor using two parameters.








I also want to make a 2D array of these objects.








What is the syntax for this?








If I type:












Java Code:











Obj[][] myObj = new Obj[10][10];

















Does this automatically run the constructor and assign these objects to the array? Or are the elements left empty (Just the memory allocated for the objects?)



Can I then go on make a loop and create objects for the array in a way similar to this (Not a loop in the example):












Java Code:











myObj[0][0] = Obj(20, 100);
myObj[0][0] = Obj(24, 29);
//...
















No comments:

Post a Comment