Sun Java Solaris Communities My SDN Account Join SDN
 
Quizzes

Building an Application Quiz - Part 3 and 4

 

Duke

Test what you learned about handling exceptions, writing to and reading from files, and accessing data. This quiz is based on the Building an Application tutorial series parts 3 and 4. The questions are aimed at beginning to intermediate developers.

Choose the most appropriate choice for each question below.

  1. How do you access private data?
     A. By initializing the class that defines the data and calling the data variable by name:
    MyClass mc = new MyClass();
    mc.namefield("Mary Smith");
    
     B. By calling public get or set methods of the class that contains the data:
    MyClass mc = new MyClass();
    mc.setNameField("Mary Smith");
    
     C. None of the above.

  2. You initialize an object from a predefined class of the Java API by calling the class constructor with the keyword new. Can a class have more than one constructor?
     A. Yes. In fact, many of them do.
     B. No. Each class is allowed only one constructor.

  3. You can access some fields or methods without initializing the class that defines them. Instead you need only name the class and call the field or method with the dot operator:
    Color.white
    

    The reason is because the method or field is

     A. static
     B. final
     C. private
     D. None of the above.

  4. If you want all instances of a class to share the value of some variable, you need to declare the value as
     A. volatile
     B. static
     C. final
     D. None of the above.

  5. Interfaces declare methods, but they do not
     A. define fields of any kind.
     B. define any methods.

  6. If your class implements an interface with abstract methods, you are promising to
     A. define a specific method or methods in your class.
     B. initialize the interface in your class.
     C. None of the above.

  7. An event listener is an object that
     A. defines what the component should do when it fires.
     B. is notified when an event occurs.
     C. None of the above.

  8. When a user fires an event through a GUI component, a method call is made to any objects that have been
     A. registered with the component as listeners for the type of event that took place.
     B. initialized within the parent class.
     C. actionPerformed method.
     D. None of the above.

  9. If your class implements the ActionListener interface, you must provide the details for the

     A. addActionListener method.
     B. getButtonFunctionality method.
     C. actionPerformed method.
     D. None of the above.

  10. Can you access a non-static inner class without creating an instance of the enclosing class?
     A. Yes.
     B. No.


  11. Does an non-static inner class have direct access to the instance variables and methods of the enclosing class without having to reference a handle or variable?

     A. Yes.
     B. No.


  12. An error indicates
     A. nonfatal conditions that you can frequently catch and handle.
     B. serious problems that a reasonable application should not try to catch.
     C. None of the above.


  13. To prepare for possible conditions, where should you write code to open a file for reading?
     A. In the main method.
     B. In its own class.
     C. In a catch clause.
     D. In a try clause.
  14. When you associate an object with the class below, allows you can perform checks on a file or directory:
     A. File
     B. FileWriter
     C. FileReader


  15. The following class improves performance of an associated Reader object by providing a temporary storage buffer.
     A. FileReader
     B. BufferedReader
     C. Reader
     D. None of the above.


  16. The finally block executes after the try/catch block is complete,
     A. only if an exception has occurred.
     B. only if an exception has not occurred.
     C. whether or not an exception has occurred.


  17. Generally, when an single-threaded application like the Dive Log runs and a JOption dialog pops up, no other action can be taken within the application until the dialog is dealt with, either by entering information, clicking a button, or closing the dialog box.
     A. True.
     B. False.

  18. When implementing an object of JScrollPane, policies refer to
     A. the size of the window enclosing the scroll pane.
     B. the columns and rows of the text area within the scroll pane.
     C. properties, such as whether scroll bars should always be available or only when needed.
     D. None of the above.

  19. Because a dialog box pops up with its own frame, you need to assign it to a container of some kind and reference it to the parent container (specifically the object calling it) of the application invoking it. Which class has a method that serves this purpose?
     A. Component
     B. Container
     C. JFileChooser

  20. After reading from and writing to files, call the flush and close methods to
     A. ensure that the buffer is emptied and the file is closed.
     B. ensure that no errors were thrown.
     C. ensure that garbage collection takes place.
     D. None of the above.