CIT591 Midterm Exam
Fall, 2005
Name_________________________________________

Please keep all your answers short and to the point. Do not provide extra information that was not asked for.

  1. (8 points) Display could be the name of a _______________ or _______________, while display could be the name of a _______________ or _______________.

  2. (2 points) "Variables should have meaningful names." Mention one exception to this rule.


  3. (4 points) Rewrite the following code fragment, using the style rules defined for this CIT591 class. Use a box () to indicate a space.
    if(X>Y){X=Math.sqrt(X-Y)+Y;}




  4. (4 points) A method declared in an interface is implicitly _______________ and _______________.

  5. (4 points) If your only constructor for a class takes an int parameter, what must be true of all the subclasses of that class?



  6. (6 points) Circle the statement types that require the use of { } braces.
    while if-then switch
    do-while for try-catch
  7. (2 points)Which package is automatically imported into every Java program?


  8. (6 points) Tell what is printed by each of the following:
    1. for (int i = 4; i < 10; i += 2) { System.out.print(i + " "); }


    2. int i = 4; while (i < 10) { i++; System.out.print(i + " "); }


    3. int i = 4; do { System.out.print(i + " "); i++; } while (i < 10);


  9. (15 points) True or False:
    1. _____ You can write a constructor for an abstract class.
    2. _____ You can create an instance of an abstract class.
    3. _____ If AbsClass is an abstract class, the expression x instanceof AbsClass is always false.
    4. _____ You can declare a constructor in an interface.
    5. _____ You can override an inherited method to make it private.
    6. _____ You can override an inherited method and throw additional checked exceptions.
    7. _____ You can override an inherited method and throw fewer checked exceptions.
    8. _____ It is legal to have methods void foo(String x) and int foo(Object x) in the same class.
    9. _____ It is legal to have methods void foo(String x) and int foo(String y) in the same class.
    10. _____ Classes, methods, and instance variables can all be declared private.
    11. _____ Classes, methods, and instance variables can all be declared final.
    12. _____ A class can extend only one other class.
    13. _____ A class can implement at most one interface.
    14. _____ A member class can access private instance variables of the enclosing class.
    15. _____ A local inner class can access local variables of the enclosing method.

  10. (5 points) Given: interface Soap { int wash(String s); }
    Write a class that implements this interface.







  11. (5 points) In class Example, write a constructor Example() that calls another constructor Example(int x) with a zero argument.




  12. (3 points) What is printed by the following? (Trick question--be very, very careful!)
    int x = 0;
    for (int i = 0; i < 5; i++) { x = x++; System.out.print(x); }



  13. (5 points)In Swing, create a JFrame with a layout that looks something like the following. You can assume that buttons or something will be put in each area; that's not part of this question.




  14. (4 points) Briefly, what does it mean to say that a dialog is modal?



  15. (6 points) If you needed to check whether a completed Sudoku puzzle is correct, what would you need to check? (Answer in English, not Java code!)




  16. (3 points) Java uses several different namespaces. List three of them.



  17. (6 points) There are three main steps to using a file. What are they?



  18. (6 points) Briefly, what is the difference between:
    1. >> and >>>


    2. && and &


    3. x++ and ++x



  19. (6 points) Suppose you have a class Person with instance variables String firstName and String lastName. Override the following methods:
    1. Override toString to return a person's full name.




    2. Override equals to return true if two people (Person objects) have the same first and last names.