Exam on the rbHilash's
Java Quiz site:
Question 42
import java.awt.*;
public class TestFrame extends Frame
{
public TestFrame()
{
Button one = new Button("One");
Button two = new Button("Two");
Button three = new Button("Three");
setLayout(new FlowLayout());
add(one);
add(two);
add(three);
two.setVisible(false);
setSize(1000,1000);
setVisible(true);
validate();
}
public static void main(
String args[])
{
TestFrame tf = new TestFrame();
}
}
1) If the above code runs, the buttons - one and three are laid out in a single row from left to right with a gap in between .
2) If the above code runs, the buttons - one and three are laid out in a single row from left to right with no gap in between.
3) Code does not compile - a component can not be hidden after being added to a container.
4) Code gets compiled successfully but throws runtime Exception - a component can not be hidden after being added to a container
the given answer is 2), but I'm not sure. Default constructor of the FlowLayout sets the horizontal gap to 5. So, the gap between the buttons 'one' and 'three' will be 5. Am I right?