CIT 591 Second Quiz
Fall 2001, Dave Matuszek
Name     Answer key
  1. Assume that i is an int variable and d is a double variable. Answer each of the following eight questions with YES or NO.
      Is this a syntax error? Could this cause a runtime error?
    i = 3.5 * d; YES NO
    d = 3.5 * i; NO NO
    i = (int) (3.5 * d); NO YES
    d = (double)(3.5 * i); NO NO

  2. For each of the following numbers, tell whether it is octal, decimal, or hex.
    0x77   hex 0   octal
    047   octal
    77   decimal  

  3. Consider the following program:
    class Test {   
        public static void main(String args[]) {
            int foo = 5;
        static void foo(int bar) {
    1. What is the name of the actual parameter to method foo?   foo

    2. What is the name of the formal parameter to method foo?   bar

    3. In main, what kind of variable is foo? (Besides int!)   local, or method

    4. What two values does this print? (Write them in the correct order.)   5  5

    5. What would happen in the above program if method foo were not declared static?   syntax error (reference to non-static method in static context)

    6. Both the method and the variable can be named foo because these names are kept in different   namespaces .
  4. Short answer:
    1. What is a glyph?  The printed (or visible) representation of a character

    2. System.out.print will print any object, but the result may not be useful. What method must you define in order to control how an object is printed?  public String toString( )