PLEASE, DON'T! | CSCI A201/A597/I210 Final Exam Spring Semester 2003 |
| Exam is closed-book, closed-notes, and individual work. | |
All
correct
answers are worth exactly one point. Leaving a question unanswered will count
as a zero. There is no penalty for guessing. DO NOT MARK more than one answer
for each question.
The test is closed-book and closed-notes.
Good luck and do well!
1. Consider the following program:
|
A. The program will compile and run.
B. The code will not compile because Beta has no default no-arg constructor.
C. The code does not compile because Beta is abstract.
D. The code does not compile because Tester does not inherit from Alpha.
E. None of the above.
2. Which of the following statements about arrays is true?
A. All of the elements in an array must be of the same type. |
For the next two questions please consider the following method:
Please answer the following two questions:
3. What does fun(4) evaluate to? A. 4 |
4. What does fun(5) evaluate to?
A. 4 |
5. After the following statement is executed,
which of these numbers could NOT possibly be contained in x?int x = (int)(Math.random() * (12 - 5) + 6); A. 6 |
6. Assuming that the following program fragment is syntactically correct...
... select the correct header for method fun.int[] a = new int[10]; ... a[0] = fun(a, a); A. |
7. What does mix("abc", "def") return if mix is defined as below?
Please choose one of the options listed below:
A. |
|
8. What gets printed when you compile and run the following program?
Choose one of the following options:
A. 1 |
9. If you compile and run this code, what is the output?
Choose one of the following:
A. |
10. If you compile and run this code, what is the output?
Choose one of the following:
A. |
11. Consider the following fragment. What does it print?
Choose among the following:
A. |
12. You compile this program ...
... then run it as follows:
What does the program print (if anything)?java One this is my song for the asking A. |
13. If you compile and run this code, what is the output?
| |
A. | |
14. If you compile and run this code, what is the output?
| |
A. | |
15. Does this source code compile?
| |
A. | |
16. Does this source code compile?
| |
A. | |
17. Does this source code compile?
| |
A. | |
| 18. What does the following program's output most closely resemble? | |
| |
Choose from the following:
A. | |
class Alpha {
public static void main(String[] args) {
Beta f = new Beta();
}
Alpha(int i) { }
}
class Beta extends Alpha { }
Choose from one of the options below:
A. The code does not compile becauseBetadoes not define a no-args constructor.
B. The code does not compile becauseBetadoes not define any constructors whatsoever.
C. The code compiles and runs succesfully, with no output.
D. The code does not compile becauseAlphadoesn't define a no-args constructor.
E. None of the above.
class Alpha {
public static void main(String[] args) {
Beta f = new Beta(3);
}
Alpha (int i) { }
}
class Beta extends Alpha {
Beta(int i) {
}
}
Choose one of the options below:
A. The code does not compile becauseBeta's constructor is empty.
B. The code does not compile becauseAlphadoesn't define a no-args constructor.
C. The code compiles and runs succesfully.
D. The code does not compile because Beta does not define a no-args constructor.
E. None of the above.
class Alpha {
public static void main(String[] args) {
Beta f = new Beta(3);
}
Alpha() { System.out.println(0); }
Alpha(int i) {
System.out.println(i);
}
}
class Beta extends Alpha {
Beta() { }
Beta(int i) { }
}
Please choose one of the options listed below:
A.The code does not compile becauseBeta's constructors are empty.
B. The code compiles and runs succesfully, but there is no output.
C. The code compiles and runs succesfully, and outputs0.
D. The code compiles and runs succesfully, and outputs3.
E. None of the above.
class Alpha {
public static void main(String[] args) {
Beta f = new Beta(3);
}
Alpha() {
System.out.println(0);
}
Alpha(int i) {
System.out.println(i);
}
}
class Beta extends Alpha {
Beta() {
super(6);
}
Beta(int i) {
this();
}
}
Please choose one of the options listed below:
A. The code compiles and runs succesfully, and outputs0.
B. The code compiles and runs succesfully, and outputs3.
C. The code compiles and runs succesfully, and outputs6.
D. The code does not compile because at least one ofBeta's constructors is not defined legally.
E. None of the above.
23. What is the result of attempting to compile and run this code?
Please choose one of the options listed below:
A. The code compiles and runs succesfully, and outputs |
| 24. How many instance methods do you see defined below? | |||
|
A. 0 | ||
| 25. How many static methods do you see defined below? | |
| |
Choose from the options listed below:
A. 0 | |
| 26. How many instance variables do you see defined below? | |
| A. 0 |
| 27. How many instance variables do you see defined below? | |
| A. 0 |
| 28. How many instance variables do you see defined below? | |
|
B. 1 C. 2 D. 3 E. none of the above |
| 29. How many local variables do you see defined below? | |
|
A. 0 |
| ||||
| 31. You compile and run this program. What's the output? | |
|
Please choose from the options listed below:
A. |
| 32. What is the output produced by the following code when embedded in a complete program? | |
| A. |
| 33. What is the output produced by the following code when embedded in a complete program? | |
| A. |
| 34. What is the output produced by the following code when embedded in a complete program? | |
| A. |
| 35. What is the output produced by the following code when embedded in a complete program? | |
| A. |
| 36. What is the output produced by the following code when embedded in a complete program? | |
| A. |
| 37. What is the output produced by the following code when embedded in a complete program? | |
|
A. true B. false
|
| 38. What is the output produced by the following code when embedded in a complete program? | |
| A. |
| 39. What is the output produced by the following code when embedded in a complete program? | |
| A. |
| 40. What is the output produced by the following code when embedded in a complete program? | |
| A. |
i = 0;
sum = 0;
while (i < 100) {
sum += i;
i += 2;
}
Assume that i and sum have been declared already.
A.for (i = sum = 0; i < 100; sum += i, i += 2) ;
B.for (i = 0, sum = 0; i < 100; i += 2) sum += i;
C.for (i = sum = 0; (i += 2) < 100 ; ) sum += i;
D.for (i = sum = 0; i < 100; sum += i) i += 2;
E.for (i = sum = 0; i < 100; i += 2) sum += i;
42. What does the following program's output look like?
Please choose from the options below:
A. a long line of numbers |
Warning: Don't overlook the logical negation (bang!) at the front.!(((x > 0) || (x == 0)) && (x < 10))
A.true
B.(x != 0) || (x >= 10)
C.false
D.(x < 0) || (x >= 10)
E.(x < 0) && (x >= 10)
44. Assume that x is an integer variable. Simplify the following boolean expression.
Warning: Don't overlook the logical negation (bang!) at the front.!(((x > 0) || (x == 0)) || (x < 10)) A. |
| 45. You compile and run the following program. What does it print? | |
| A. |
46. Consider the following condition.
Which of the following represents a simplification of it (obtained perhaps using DeMorgan).! (x % 3 != 0 || x % 2 != 0) | |
A. | |
47. Assume a is of type boolean and consider the following condition.
Which of the following represents a simplification of it.(! (a && !a)) == false | |
A. | |
48. Consider the following program fragment.
What value does y have at the end?int x = 1, y = 1; if (x < 2) if (x > 1) y = 2; else y = 3; else y = 4; | |
A. | |
49. Consider the following program fragment.
What value does y have at the end?int x = 1, y = 1; if (x > 2) y = 2; y = y + 1; else y = y + 1; | |
A. | |
50. Consider the following program fragment.
What value does y have at the end?
| |
A. | |
51. Consider the following program fragment.
What value does y have at the end?int x = 1, y = 1; if (x < 2) y = 2; else y = y + 1; y = y - 1; | |
A. | |
52. How many question marks will be printed by the following code fragment?
| |
A. | |
A201/A597/I210 Final Exam Tue May 6 5-7pm 2003 in RH100