Which checkboxes will initially be selected when the following program is run?
import java.awt.*;
public class TestClass extends Frame
{
TestClass( )
{
setLayout(new FlowLayout());
CheckboxGroup[] cbgs = new CheckboxGroup[] { new CheckboxGroup(), new CheckboxGroup()};
for (int i=0; i<5; i++) add( new Checkbox("Checkbox"+i, true, cbgs[i%2] ) ); //1
setSize(300, 300);
setVisible(true);
}
public static void main(
String[ ] args)
{
new TestClass();
}
}
It says that checkboxes 3 and 4.
But I think that at line marked 1 when it will calculate cbgs[i%2] in its fourth iteration, program should throw an ArrayIndexOutOfBoundsException as result will be 2.
Correct me if wrong.
Tanveer