What ispreferred way to handle an object’s events i Java 2

Discussion in 'Computer Science and IT Students' started by mansi, Mar 31, 2006.

  1. mansi

    mansi Guest

    JAVA OBJECTIVE QUIZ - 4 Questions

    1. Which of the following are Flase?

    The Serializable interface is used to identify objects that may be written to an output stream
    The Externalizable interface is implemented by classes that control the way in which their objects are serialized
    The Serializable interface extends the Externalizable interface
    The Externalizable interface extends the Serializable interface

    --------------------------------------------------------------------------------


    2. Which of the following are False about the File class?
    A File object can be used to access the files in the current directory.
    When a File object is created, a corresponding directory or file is created in the local file system
    File objects are used to access files and directories on the local file system
    File objects can be garbage collected.

    --------------------------------------------------------------------------------


    3. Which of the following are true
    Writer classes can be used to write Unicode characters to output streams
    Writer classes have methods that support the writing of the values of any Java primitive type to output streams
    Writer classes have methods that support the writing of objects to output streams.

    none of the above


    --------------------------------------------------------------------------------


    4. How do you create a Reader object from an InputStream object
    Use the static createReader( ) method of InputStream class
    Use the static createReader( ) method of Reader class.
    Create an InputStreamReader object, passing the InputStream object as an argument to the InputStreamReader constructor.
    Create an OutputStreamReader object, passing the InputStream object as an argument to the OutputStreamReader constructor

    --------------------------------------------------------------------------------


    5. Which of the following features are non-common to both Java & C++?

    The class declaration
    The access modifiers
    The encapsulation of data & methods with in objects
    The use of pointers


    --------------------------------------------------------------------------------


    6. What tags are mandatory when creating HTML to display an applet
    name, height, width
    code, name
    codebase, height, width

    code, height, width

    --------------------------------------------------------------------------------


    7. Which of the following are false?
    A TextField object may generate an ActionEvent
    A TextArea object may generate an ActionEvent
    A Button object may generate an ActionEvent
    A MenuItem object may generate an ActionEvent

    --------------------------------------------------------------------------------


    8. Which of the following are true?
    The MouseListener interface defines methods for handling mouse clicks
    The MouseMotionListener interface defines methods for handling mouse clicks
    The MouseClickListener interface defines methods for handling mouse clicks
    None of these

    --------------------------------------------------------------------------------


    9. Which of the following are true?
    The event-inheritance model has replaced the event-delegation model.

    The event-inheritance model is more efficient than the event-delegation model
    The event-delegation model uses event listeners to define the methods of event-handling classes
    The event-delegation model uses the handleEvent( ) method to support event handling.

    --------------------------------------------------------------------------------


    10. Which of the following components generate action events?
    Buttons
    Labels
    Check boxes

    Windows


    --------------------------------------------------------------------------------


    11. What code would you use to construct a 24-point bold serif font
    new Font(Font.SERIF, 24,Font.BOLD);

    new Font("SERIF", 24, BOLD");
    new Font("BOLD ", 24,Font.SERIF);

    new Font("SERIF", Font.BOLD,24);


    --------------------------------------------------------------------------------


    12. Which of the following are passed as an argument to the paint( ) method
    A Canvas object

    A Graphics object

    An Image object

    A paint object


    --------------------------------------------------------------------------------


    13. Which method is used to set the text of a Label object?

    setText( )

    setLabel( )

    setTextLabel( )

    setLabelText( )


    --------------------------------------------------------------------------------


    14. suppose that you want to have an object eh handle the TextEvent of a TextArea object t. How should you add eh as the event handler for t?

    t.addTextListener(eh);

    eh.addTextListener(t);

    addTextListener(eh.t);
    addTextListener(t,eh);


    --------------------------------------------------------------------------------


    15. What is the preferred way to handle an object’s events in ?
    Override the object’s handleEvent( ) method.
    Add one or more event listeners to handle the events.
    Have the object override its processEvent( ) methods
    Have the object override its dispatchEvent( ) methods

    --------------------------------------------------------------------------------


    16. Which of the following are true?

    A component may handle its own events by adding itself as an event listener
    A component may not handle oits own events.
    A component may handle its own events only if it implements the handleEvent( ) method
    None of these


    --------------------------------------------------------------------------------


    17. How would you set the color of a graphics context called g to cyan?
    g.setColor(Color.cyan);

    g.setCurrentColor(cyan);
    g.setColor("Color.cyan");
    g.setColor(new Color(cyan));


    --------------------------------------------------------------------------------


    18. The code below draws a line. What color is the line?

    g.setColor(Color.red.green.yellow.red.cyan);

    g.drawLine(0, 0, 100,100);
    RED

    YELLOW
    BLACK
    CYAN

    --------------------------------------------------------------------------------


    19. What does the following paint( ) method draw?

    Public void paint(Graphics g) {

    g.drawString("question #6",10,0);
    A circle at (100, 100) with radius of 44

    A circle at (100, 44) with radius of 100

    A circle at (100, 44) with radius of 44
    The code does not compile


    20. Which of the following methods are invoked by the AWT to support paint and repaint operations?
    paint( )
    repaint( )

    draw( )

    redraw( )

Share This Page