| 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: 4 |
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: A C B A B C B A C C B A |
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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
// Write the header line for a public class that extends JFrame
public class Test2 extends JFrame{
// Declare and define a Swing button, a Swing text field, and
// an int to count clicks
JButton button = new JButton("Click me");
|
/* 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 */ }
public.
Why?foo with its original value of 12,
you could put a print statement between lines 17 and 18 .final on line 9 have?s1.ace() 1 |
s1.twice(3) 6 |
s1.number() 11 |
s2.ace() 13 |
s2.twice(3) 6 |
s2.number() 10 |
s1.foo 16 |
s1.dubble(6) illegal |
s1.dubble("8") 88 |
s2.foo 16 |
s2.dubble(7) illegal |
s2.dubble("9") 99 |
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.
/** |
|
Do not:
|
Do:
|
| Sample answer: /** * Handles an input digit. * @param digit The digit to be handled. * @return A string representing the current state of the calculation. */ |
|