Site hosted by Angelfire.com: Build your free website today!
Java Quiz




Question 41.

    Read the following piece of code carefully.
 

 import java.awt.*;

 public class TestFrame extends Frame
 {
      Button firstOne = new Button("One");
      Button secondOne = new Button("Two");

      public TestFrame()
      {
           add(firstOne,BorderLayout.NORTH);
           add(secondOne,BorderLayout.NORTH);

           setSize(400,400);
           setVisible(true);
      }
      public static void main(String args[])
      {
           TestFrame tf = new TestFrame();
      }
 }


 An Attempt  to compile and  run the above piece of code
 

  1. Causes compilation error - a component cannot be added to region which is already occupied by another component.
  2. Causes Runtime Exception - a component cannot be added to region which is already occupied by another component.
  3. Neither i or ii. The Frame comes up and only the button with label "Two" occupies the entire North region of the Frame.
  4. Addition of secondOne causes firstOne to be removed from the container.
  5. Addition of the secondOne causes the firstOne to be hidden in the container.

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.

Question 43.

     Read the code below carefully.
 

import java.awt.*;

 public class TestFrame extends Frame
 {
      public TestFrame()
      {
           setLayout(new GridLayout(2,1));
           for(int i = 1 ; i <= 4 ;++i)
           {
               add(new Button(Integer.toString(i)));
           }

           pack();
           setVisible(true);
      }

      public static void main(String args[])
      {
           TestFrame tf = new TestFrame();
      }
 }

  1. The code above will not compile  - The number of components added is more than the magnitude of row * columns of the Grid Layout Manager.
  2. The code will throw a runtime Exception  - The number of components added is more than the magnitude of row * columns of the Grid Layout Manager.
  3. The code will compile cleanly and when run Four buttons are visible in 2 rows and 2 columns.
  4. The code will compile and when run, Four buttons are seen in a single Column.

Question 44.

    Read the code below carefully.
 

 import java.awt.*;

 public class TestFrame extends Frame
 {
      public TestFrame()
      {
           setLayout(new GridLayout());
           for(int i = 1 ; i <= 4 ;++i)
           {
                add(new Button(Integer.toString(i)));
           }

           pack();
           setVisible(true);
       }

      public static void main(String args[])
      {
           TestFrame tf = new TestFrame();
      }
 }

  1. The code will not compile - the grid layout does not have a no-argument constructor..
  2. The code compiles and when run all the buttons are seen in a single column.
  3. The code compiles and when run all the buttons are seen in a singe row.
  4. The code compiles and when run all button are added one on top or another and only the last one added is visible.
  5. The code compiles , but throws a runtime Exception when components are added.

Question 45.

     Which of the following statements are true about setLayout() method in java.awt.ScrollPane
 

  1. Does nothing.
  2. Throws UnsupportedMethodException when called.
  3. It is not overriden in java.awt.ScrollPane.
  4. Sets the layout to the specified Layout Manager.

Question 46.

    An Outer class which has all its constructors declared as private

  1. Cannot be instantiated by any other Outer class.
  2. Cannot be extended.
  3. Both i and ii.
  4. has to be declared final.

Question 47.

     The GridBagConstraints Class

  1. Is serializable.
  2. Is cloneable.
  3. belongs to the java.awt package.
  4. extends Object.

Question 48.

    Read the following code carefully
 

import java.awt.*;
public class TestFrame extends Frame
{
         public TestFrame()
        {
                CheckboxGroup chg = null;
                Checkbox ch = new Checkbox("Test",true,chg);

                setLayout(new FlowLayout());
                add(ch);
                pack();
                setVisible(true);
          }
        public static void main(String args[])
        {
            TestFrame tf = new TestFrame();
        }
}


    An Attempt to compile and run the above code

  1. will cause a compilation error as the checkbox group is null in the constructor.
  2. will compile successfully but throws a runtime exception because the checkbox group is null in the constructor of the check box
  3. will compile and run successfully. The checkbox appears as a single radio button which is always true.
  4. will compile and run successfully. The checkbox bears its original appearence and does not appear as a radio button.

Question  49.

    Read the following code carefully
 

import java.awt.*;
public class TestFrame extends Frame
{
         public TestFrame()
        {
                CheckboxGroup chg = new CheckboxGroup();
                Checkbox ch = new Checkbox("Test",true,chg);

                setLayout(new FlowLayout());
                add(ch);
                pack();
                setVisible(true);
          }
        public static void main(String args[])
        {
            TestFrame tf = new TestFrame();
        }
}


    An Attempt to compile and run the above code

  1. will cause a compilation error as the checkbox group contains only one checkbox.
  2. will compile successfully but throws a runtime exception because the checkbox group contains only one checkbox.
  3. will compile and run successfully. The checkbox appears as a single radio button which is always true.
  4. will compile and run successfull. The checkbox bears its original appearence and does not appear as a radio button.

Question  50.

Which of the following methods of the java.io.File class throws a checked Exceptions -
 

  1. getCanonicalPath()
  2. getCanonicalFile()
  3. getAbsolutePath()
  4. getAbsoluteFile()
  5. createTempFile()
  6. createNewFile()
  7. mkdir()
  8. mkdirs()
  9. toURL()

If you have any concerns regarding any of the questions in this page, please mail me NOW!