Java Awt Part II

 

JAva AWT

Q1.   The Container methods add( Component comp ) and add( String name, Component comp) will throw an IllegalArgumentException
if
comp is a:
a) button
b) list
c) window
d) textarea
e) container that contains this container

 

Q2.               Of the following AWT classes, which one(s) are responsible for implementing the components layout?

a) LayoutManager//interface implementd by all classes
b) GridBagLayout
c) ActionListener
d) WindowAdapter
e) FlowLayout

 

 

Q3.               A component that should resize vertically but not horizontally should
be placed in a:

a) BorderLayout in the North or South location
b) FlowLayout as the first component
c) BorderLayout in the East or West location
d) BorderLayout in the Center location
e) GridLayout

Q4.               What type of object is the parameter for all methods of the
MouseListener interface?//MouseEvent e

Q5.               Which of the following statements about event handling in JDK 1.1 and
later are true?

a)A class can implement multiple listener interfaces
b) If a class implements a listener interface, it only has to overload the methods it uses
c) All of the MouseMotionAdapter class methods have a void return type.

Q6.               Which of the following describe the sequence of method calls that result in a component being redrawn?

a) invoke paint() directly
b) invoke update which calls
paint()
c) invoke
repaint() which invokes update(), which in turn invokes paint()
d) invoke repaint() which invokes paint directly

Q7. What is Swing?//swing is top class to all awt

//swing components are lightweight

Q8) What are peer "classes"?//displays the AWT components as the operating system’s graphical capability

Q9. Which of the following are valid constructors for a TextField .
 
1. TextField();
2. TextField(int rows , int cols);
3. TextField(int cols , String txt); 
4. TextField(int cols);
5. TextField(String txt , boolean scrollBars);
 
Q10. What is the default layout for a Dialog ?
 
1. FlowLayout
2. GridLayout
3. CardLayout
4. BorderLayout
5. GridBagLayout
 
Q11. True or false.
      A Dialog is a subclass of Frame. 
 
1. True
2. False
 
12. Which of the following are valid constructors for a MenuItem ?
1. MenuItem()
2. MenuItem(String name)
3. MenuItem(String name , boolean removable)
4. MenuItem(String name , MenuShortcut sc)
5. MenuItem(boolean check)

Q13.                    Please select the size of an int  type

A.                       32 bytes

B.                        16 bits

C.                       32 bits

D.                       16 bytes

Q14.        Select default value of boolean type

a.   true

b. false

c.   0

d.  1

Q15)Can Innerclass  access a outer class member variable?
 
public class OuterClass
{
         int outerVariable = 100;
          class MemberClass 
         {
                          int innerVariable = 20;
                  int getSum(int parameter) 
                 {
                   return innerVariable +  outerVariable + parameter;
                  }       
          }
             public static void main(String[] args) 
         {
                 OuterClass outer = new OuterClass();
                 MemberClass inner = outer.new MemberClass(); 
                 System.out.println(inner.getSum(3));
                  outer.run();
          }
          void run()
         {
                 MemberClass localInner = new MemberClass();
                 System.out.println(localInner.getSum(5));
          }
}

 

Q 16) What is the advantage of Anonymous Inner class”

Q17) Can u have inner class as static?

public class OuterClass

{

       int outerVariable = 100;

       static int staticOuterVariable = 200;

 

       static class StaticMemberClass

        {

          int innerVariable = 20;

             int getSum(int parameter)

             {

                // Cannot access outerVariable here

                 return innerVariable + staticOuterVariable + parameter;

            }      

        }

    

       public static void main(String[] args)

       {

            OuterClass outer = new OuterClass();

            StaticMemberClass inner = new StaticMemberClass();

           System.out.println(inner.getSum(3));

           outer.run();

       }

    

        void run()

       {

            StaticMemberClass localInner = new StaticMemberClass();

           System.out.println(localInner.getSum(5));

       }

}

 

Que-18)What is local inner class?


 public class OuterClass3

{

    int outerVariable = 10000;

    static int staticOuterVariable = 2000;    

    public static void main(String[] args)

   {

        OuterClass3 outer = new OuterClass3();

        System.out.println(outer.run());

    }    

    Object run()

   {

        int localVariable = 666;

        final int finalLocalVariable = 300;        

        class LocalClass

        {

            int innerVariable = 40;

              int getSum(int parameter)

       {

                     // Cannot access localVariable here

                     return outerVariable + staticOuterVariable +  finalLocalVariable + innerVariable + parameter;

            }      

        }

        LocalClass local = new LocalClass();

        System.out.println(local.getSum(5));

        return local;

    }

}

 Que 19)

class  Outer

{

       private void Outer()

       {

       }

       protected class Inner

       {

       }

}

Select one correct answer

a)This code will not compile

b)Constructor for  Outer is public

c)Constructor for Outer is private

d)Constructor for Inner  ispublic

e)Constructor for Inner is protected

 

Q20) Can u have public private protected  declared with local inner class