Written Portion of Exam 1 - Sample
Answer all of the following questions. This is an "open book" exam,
but you must work entirely on your own.
-
(10 points)
Choose the best answer to each of the following:
(1) |
_____
|
In Java, < is |
|
|
- A relational operator
- A unary operator
- A distributed operator
- All of the above
- None of the above
|
(2) |
_____
|
In Java, &&
|
|
|
- Is a logical operator
- Is a binary operator
- Has
boolean operands
- All of the above
- None of the above
|
(3) |
_____
|
In Java, 'J'
|
|
|
- Is a
String literal
- Is a
String variable
- Is a
char literal
- Is a
char variable
- None of the above
|
(4) |
_____
|
In Java, a variable is |
|
|
- The implicit loss of precision in arithemtic operations
- The way the decrement operator changes
- A named space for holding a value
- All of the above
- None of the above
|
(5) |
_____
|
In the Java statement
i =
(int)d; the operator = is
a/an: |
|
|
- Assignment operator
- Relational operator
- Typecast operator
- All of the above
- None of the above
|
(6) |
_____
|
In the Java statement
i = (int)d; the (int)
operator is a/an: |
|
|
- Assignment operator
- Relational operator
- Typecast operator
- All of the above
- None of the above
|
(7) |
_____
|
In the Java statement
i = (int)4.0; the operand of the
(int) operator is a/an: |
|
|
- Assignment operator
- Literal
- Typecast operator
- All of the above
- None of the above
|
(8) |
_____
|
In Java, what kind of statement
is int i; ? |
|
|
- Assignment statement
- Declaration statement
- Typecast statement
- All of the above
- None of the above
|
(9) |
_____
|
In Java, an if
statement must
syntactically (not according to the style guide) contain which
of the following? |
|
|
- Curly brackets
- A
boolean expression in parentheses
- An
else clause
- All of the above
- None of the above
|
(10) |
_____
|
In Java, the main() method of the "main class"
must have what return type? |
|
|
-
double
-
int
-
String
-
void
- None of the above
|
-
(20 points)
Consider the following fragment (written in Java):
public class Calculator {
public static final int MAX_SIZE = 100;
public static double circumference(double radius) {
double result;
result = 2.0 * Math.PI * radius;
return result;
}
}
Identify the best description of each of the following as it is used
in this fragment. You may use a description more than once.
|
- An actual parameter
- An arithmetic operator
- A "class constant"
- The command-line arguments
- A formal parameter
- A literal
- A local variable
- A logical operator
- The membership operator
- The name of a class
- The name of a method
- A relational operator
- A typecast operator
|
-
(10 points)
Each of the following is supposed to be
written in Java, however some may contain syntax errors. For
those expressions that are syntacticaly correct, indicate what
they evaluate to. For those that are not syntactically correct,
write ERROR.
true && (false || true)
|
|
|
5 > (0 && 1)
|
|
|
(5 < 3) || (5 > 3)
|
|
|
!(false && false)
|
|
|
3 < 4 < 5
|
|
|
-
(5 points)
Choose the best answer to each of the following:
(1) |
_____
|
In Java, the statement
doubl cost;
|
|
|
- A compile-time error
- A run-time error
- A repetitive stress error
- All of the above
- None of the above
|
(2) |
_____
|
In a Java program written for CS149, omitting a
period from the end of the first line of a comment
will cause which of the following? |
|
|
- A compile-time error
- A run-time error
- A Checkstyle error
- All of the above
- None of the above
|
(3) |
_____
|
In Java, assuming that the variables have been both
declared and initialized, the statement
average = total / 0; will cause
which of the following? |
|
|
- A compile-time error
- A run-time error
- A repetitive stress error
- All of the above
- None of the above
|
(4) |
_____
|
In Java, assuming that the variables have been both
declared and initialized, the statement
average = 0 / count; will cause
which of the following? |
|
|
- A compile-time error
- A run-time error
- A repetitive stress error
- All of the above
- None of the above
|
(5) |
_____
|
In Java, assigning an int literal to
a variable that was declared to be a double will cause
which of the following? |
|
|
- A compile-time error
- A run-time error
- A repetitive stress error
- All of the above
- None of the above
|
-
(5 points)
Provide a concise comparison of the two terms in each of the following.
Actual parameters and formal parameters
|
|
|
Declaration and assignment
|
|
|
double and int
|
|
|
The @param tag and the @return tag
in a Javadoc comment
|
|
|
Class and method
|
|
|