| CIT591 Final Exam Fall, 2004 |
Name_________________________________________ |
Please keep all your answers short and to the point. Do not provide extra information that was not asked for.
int n = 2004; |
Answer: |
String[] strings = new String[] { "A ", "B ", "C "};
for (int i = 0; i < strings.length; i++) {
System.out.println(strings[i]);
for (int j = 2; j >= 0; --j) {
System.out.print(strings[j]);
}
}
|
Answer: |
int x = 100, what is the value of each of the
following expressions?
|
|
break
statement be used?continue
statement be used? assert false; in a well-written
program, what was the programmer probably trying to indicate? assert statement?class MyClass extends ThatClass {...}class MyClass { ThatClass that; ...}
// Import all the necessary packages
// Write the header line for a public class that extends JFrame
// Declare and define a Swing button, a Swing text field, and
// an int to count clicks
// Write the header line for your main method
// Create a new instance of this class, and call its createGui() method
} // end main
// Write the header line for the createGui() method
// Get this JFrame's content pane, and assign it to a variable
// Set a layout manager
// Add the text field and button to the GUI
// Attach a listener of type "Listen" to the button
// Pack this GUI and make it visible
} // end createGui
// Declare an inner class "Listen" which implements ActionListener
// Declare the required method for an ActionListener
// Add one to the click count and display the result
} // end method
} // end inner class
} // end outer class
|
/* 1 */ interface MyInterface {
/* 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 MainClass {
/* 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 MainClass extends Abs implements MyInterface {
/* 16 */ public int number() { return 11; }
/* 17 */ public static void main(String args[]) {
/* 18 */ MainClass s1 = new MainClass();
/* 19 */ MainClass s2 = new Sub(16);
/* 20 */ System.out.println( );
/* 21 */ }
/* 22 */ int twice(int x) { return 2 * x; }
/* 23 */ int ace() { return 1; }
/* 24 */ String dubble(String s) { return s + s; }
/* 25 */ }
| s1.ace() | s1.twice(3) | s1.number() |
| s2.ace() | s2.twice(3) | s2.number() |
| s1.foo | s1.dubble(6) | s1.dubble("8") |
| s2.foo | s2.dubble(7) | s2.dubble("9") |
char is the same as a String of length
1. public String toString() method. String[] s; does not allocate any
space.private variables of an object can be accessed
by another object of the same class.instanceof must be an object.assertEquals(expected, actual).
What restrictions, if any, are placed on the two arguments?assertEquals,
and specify what type of arguments each method expects.
/** |