CIT591 Final Exam
Fall, 2002
Name_________________________________________
  1. (18 points) First, step through the following program, updating the values of all the variables, until you get to the System.out.println statement. Then fill in the following table, telling (1) the simplest possible way to print the variable, and (2) what value will be printed for it. If a variable cannot be accessed, tell why.
    public class Major {
        int a = 1, b = 2, c = 3;
        Extra extra = new Extra();
        
        public static void main(String args[]) {
            int b = 4, d = 5;
            Minor minor = new Minor(b);
            minor.printAll();
        }
    }
    class Minor extends Major {
        int c = 6, e = 7;
        static int f = 8;
        
        Minor(int param) { b = e = param; }
        
        void printAll() {
            System.out.println(   expression from table below  );
        }
    }
    class Extra {
        int f = 9;
        Extra() { f = 10; }
        
        class Inner { int g = 11; }
        Inner inner = new Inner();
    }
    Variable Simplest expression to access variable Value
    a in Major    
    b in Major    
    b in main    
    c in Major    
    c in Minor    
    d in main    
    e in Minor    
    f in Minor    
    f in Extra    
    g in Inner    


  1. (20 points) True or false:
    1. _____ A char is just a String of length 1.
    2. _____ Methods may have a maximum of 32 parameters.
    3. _____ An abstract class cannot be instantiated.
    4. _____ Methods declared in an interface are automatically public.
    5. _____ Constants may be declared in an interface.
    6. _____ The size of an array is part of its type.
    7. _____ In BlueJ, a striped box means the class is not compiled.
    8. _____ A RuntimeException need not be caught.
    9. _____ You can attach more than one Listener to a Component.
    10. _____ You can attach a Listener to more than one Component.
    11. _____ In an if test, zero counts as false, other integers as true.
    12. _____ You can do integer arithmetic with a char variable.
    13. _____ The break statement can only be used within a loop.
    14. _____ The continue statement can only be used within a loop.
    15. _____ Applets can only be run from within a browser.
    16. _____ To create an applet, you must subclass the Applet class.
    17. _____ A Java file can legally contain more than one public class.
    18. _____ Anonymous inner classes can access the fields of the enclosing class.
    19. _____ Every method must have at least one return statement.
    20. _____ Any number that begins with a zero is considered to be octal.

  2. (10 points) Give brief definitions of the following terms:

    1. glyph

    2. wrapper class

    3. magic number

    4. Swing

    5. modal dialog

  3. (1 point) What is the default layout manager for a Panel?

  4. (1 point) What is the default layout manager for a Frame?

  5. (2 points) If array field[][] has been declared and defined as a rectangular array, write an expression that returns:

    1. The number of rows (first subscript) in the array.

    2. The number of columns (second subscript) in the array.

  6. (3 points) Write a boolean method divisible, with two integer parameters, that tests whether its first parameter is divisible by its second parameter. For full credit, keep your method body as short as possible.





  7. (2 points) Should your divisible method from the previous question be declared static? Why or why not?



  8. (1 point) How do you declare that a variable has a fixed, constant value?


  9. (4 points) What are the four conditions for serializing an object?









  10. (3 points) Give the name of the Java regular expression method that:

    1. Tries to match the entire string

    2. Tries to match at the beginning of the string.

    3. Searches the string for a match

  11. (3 points) Write a regular expression that will match an integer (the integer may be signed or unsigned).



  12. (1 point) How do you prevent a method from being overridden by a method in a subclass?



  13. (2 points) What is special about the first sentence of a Javadoc comment?



  14. (1 point) What part of speech (grammatical category) should be used when naming methods?


  15. (1 point) When do the style rules say you should not give a variable a meaningful name?



  16. (3 points) Here is a constructor for a class named Point:
         Point(float x, float y) { this.x = x; this.y = y; }
    Write a second constructor for Point that takes one parameter x and calls the above constructor with 1/2 x and twice x.



 1  interface Inter {
 2      int number();
 3  }
 4  abstract class Abs {
 5      static int foo = 12;
 6      int number() { return 5; }
 7      abstract int ace();
 8  }
 9  final class Sub extends Super {
10      Sub(int bar) { foo = bar; }
11      public int number() { return 10; }
12      int ace() { return 13; }
13      int dubble(int i) { return 2 * i; }
14  }
15  public class Super extends Abs implements Inter {
16      public int number() { return 11; }
17      public static void main(String args[]) { 
18          Super s1 = new Super();
19          Super s2 = new Sub(16);
20          System.out.println(      );
21      }
22      int twice(int x) { return 2 * x; }
23      public int thrice(int x) { return 3 * x; }
24      int ace() { return 1; }
25      String dubble(String s) { return s + s; }
26  }
  1. (2 points) In the above program, does Super correctly implement Inter? Why or why not?



  2. (2 points) In line 11, it is a syntax error to omit the word public. Why?



  3. (1 point) The method defined on line _____ overrides the method defined on line _____.

  4. (1 point) The method defined on line _____ overloads the method defined on line _____.

  5. [Question deleted.]

  6. (1 point) To print out foo with its original value of 12, you could put a print statement between lines _____ and _____.

  7. (2 points) Which of the above classes and/or interfaces have default constructors?

  8. (1 point) What effect does the keyword final on line 9 have?


  9. (12 points) At line 20, what would be printed for:
    s1.ace() s2.ace() s1.foo s2.foo
    s1.twice(3) s2.twice(3) s1.dubble(6) s2.dubble(7)
    s1.number() s2.number() s1.dubble("8") s2.dubble("9")