CIT 591 Sample Exam Questions
Fall 2003, David Matuszek
  1. What is printed when the following program is executed?
    class Super {
        int a = 10;
        static int b = 20;
        int value() { return 30;}
    }
    
    public class Sub extends Super {
        int a = 1;
        static int b = 2;
        int value() { return 3;}
        
        public static void main(String[] args) {
            Sub sub = new Sub();
            Super sup = new Super();
            Super sub2 = new Sub(); // notice this assignment
            System.out.println(sub.a + " " + sub.b);
            System.out.println(sup.a + " " + sup.b);
            System.out.println(sub2.a + " " + sub2.b);
            System.out.println(sub.value() + " " + sup.value() + " " + sub2.value());
        }
    }
  2. When should you use an assert statement?

  3. If you have a syntax error because you haven't caught a necessary Exception, how do you find out what Exception it is that you need to catch?

  4. When you are editing a file in BlueJ, the Edit menu has the usual Undo, Redo, Cut, Copy, and Paste commands. Name two other commands that are on this menu.

  5. An array is defined as int[] numbers = new int[100]. At least some of the numbers in the array are known to be negative. Write a code fragment (not a complete program!) to find the location of the last negative number in the array.