| CIT 591 Final Exam, Fall 2011 |
Name ____________________________________ |
Please keep all answers short and to the point. Do not add information that is not asked for;
you will not gain points, but you may lose points if you get it wrong. If the question asks for a statement, write a statement, not a function. If the question asks for a function, write a function, not a class. In short, read the question!
- (10 points) In the following program,
1 public class MyClass {
2 private static int a = 10;
3 private int b = 20;
4
5 public static void main(String[] args) {
6 System.out.println( ? );
7 int c = 30;
8 System.out.println( ? );
9 for (int d = 0; d < 10; d++) {
10 System.out.println( ? );
11 int e = 50;
12 System.out.println( ? );
13 new MyClass().run();
14 }
15 }
16
17 private void run() {
18 System.out.println( ? );
19 }
20 }
tell which of the variables (a, b, c, d, e, args) may be printed by each of the println statements:
println at line 6: ____________________________________________
println at line 8: ____________________________________________
println at line 10: ____________________________________________
println at line 12: ____________________________________________
println at line 18: ____________________________________________
- (5 points) For each of the following, write either "can" or "cannot" in the blank.
- Eclipse ___________ create a unit test class, complete with stub test methods.
- Eclipse ___________ display the Javadoc for both built-in functions and functions that you write.
- Eclipse ___________ find references in other classes to an instance variable declared in this class.
- Eclipse ___________ reformat your code to use tabs instead of spaces.
- Eclipse ___________ generate an
equals method for objects of a class that you have defined.
- (5 points) What is the signature of a Java method? Give a precise definition, not an example.
- (4 points) Test-driven development (TDD) encourages better code, not just code with fewer bugs. List two ways in which code written using TDD is likely to be better.
-
-
- (5 points) (True or False) In pair programming,
- __________ The navigator should tell the driver what to type.
- __________ The navigator should think ahead and keep a "big picture" view.
- __________ The navigator should tell the driver whenever he/she makes a typing error.
- __________ The driver and navigator should switch roles frequently.
- __________ The driver should talk aloud about what the code he/she is entering is supposed to do.
- (5 points) A variable
obj has been declared as Object obj; but you happen to know that it contains a String. Write an expression to return the length of the string in variable obj.
- (5 points) A class
Car has a constructor Car(String make, String model, int year). Write another constructor for Car that takes make and model parameters, and calls the first constructor with those values and a default value of 2011 for the year.
- (5 points) Draw a picture to show the various areas of a
BorderLayout. Label each area.
- (5 points) True or False: When you override a method:
- ______ You must use the same function name.
- ______ You must use the same access (public, protected,
package, or private).
- ______ You must use the same return type.
- ______ You must use the same parameter types.
- ______ You must use the same parameter names
- (10 points) If
int x = 100, what is the value of each of the
following expressions?
x / 30 |
|
x % 30 |
|
x == 99 ? 5 : 7 |
|
x & x |
|
~x |
|
|
x << 2 |
|
x >> 2 |
|
x <<< 2 |
|
x >>> 2 |
|
x ^ x |
|
|
- (5 points) Write a loop to compute the first power of 2 that exceeds one million (1,000,000) and save it in a variable named
bigPower.
- (5 points) A movie theater charges different prices for small children, students, adults, and seniors. Write an
enum to list (enumerate) these types of customer.
- (5 points) Java supplies a genericized class
ArrayList. Declare and define a variable named people that holds an ArrayList, where every value in the ArrayList must be of type Person.
- (5 points) Assume
quitButton is a JButton that has been created and displayed. Write code to call Java's exit(0) method when this button is clicked, using either a member class or an anonymous inner class (your choice).
- (5 points) What does it mean to say that an exception is checked or unchecked?
- (4 points) Complete the following sentence:
A method should be made static if...
- (4 points) What is the DRY principle, and how does it apply to data?
- (4 points) What are the four conditions for serializing an object?
-
-
- (4 points) In MVC you want the Model to be independent of the Controller and the View. To support this, Java
provides you with the ____________________ interface and the ___________________ class.