COP 3330 PRACTICE EXAM
QUESTIONS AND COMPLETE
SOLUTIONS
QUESTIONS AND ANSWERS
Consider the following Java statements:
int x = 9;
double y = 5.3;
result = calculateValue(x, y);
Which of the following statements is false?
a. A method is called with its name and parentheses.
b. x and y are parameters.
c. Copies of x and y are passed to the method calculateValue.
d. x and y are arguments.. ANSWER -B. x and y are parameters
What would be the output of following program.
class Main { public static void main(String args[]) {
try {
throw 10;
, }
catch(int e) {
System.out.println("Got the Exception " + e);
}
}
}
a. Got the Exception 10
b. Got the Exception 0
c. Compile Error
d. Throws 10. ANSWER -C. No exception of type int can be thrown; an exception type
must be a subclass of Throwable
A method is invoked with a(n). ANSWER -method call
A variable known only within the method in which it's declared is called a(n). ANSWER -
local variable
The _____ statement in a called method can be used to pass the value of an expression back
to the calling method. ANSWER -return
The keyword _____ indicates that a method does not return a value. ANSWER -void
Data can be added or removed only from the ___ of a stack. ANSWER -top
Stacks are known as ____ data structure; the last item pushed (inserted) onto the stack is
the first item popped (removed) from the stack.. ANSWER -Last-in First-out
Three ways to return control from a called method to a call are _____, ______, and ______.
ANSWER -Return, return expression, and encountering the closing right brace of a method
An object of class ____ produces truly random numbers.. ANSWER -Secure-Random
QUESTIONS AND COMPLETE
SOLUTIONS
QUESTIONS AND ANSWERS
Consider the following Java statements:
int x = 9;
double y = 5.3;
result = calculateValue(x, y);
Which of the following statements is false?
a. A method is called with its name and parentheses.
b. x and y are parameters.
c. Copies of x and y are passed to the method calculateValue.
d. x and y are arguments.. ANSWER -B. x and y are parameters
What would be the output of following program.
class Main { public static void main(String args[]) {
try {
throw 10;
, }
catch(int e) {
System.out.println("Got the Exception " + e);
}
}
}
a. Got the Exception 10
b. Got the Exception 0
c. Compile Error
d. Throws 10. ANSWER -C. No exception of type int can be thrown; an exception type
must be a subclass of Throwable
A method is invoked with a(n). ANSWER -method call
A variable known only within the method in which it's declared is called a(n). ANSWER -
local variable
The _____ statement in a called method can be used to pass the value of an expression back
to the calling method. ANSWER -return
The keyword _____ indicates that a method does not return a value. ANSWER -void
Data can be added or removed only from the ___ of a stack. ANSWER -top
Stacks are known as ____ data structure; the last item pushed (inserted) onto the stack is
the first item popped (removed) from the stack.. ANSWER -Last-in First-out
Three ways to return control from a called method to a call are _____, ______, and ______.
ANSWER -Return, return expression, and encountering the closing right brace of a method
An object of class ____ produces truly random numbers.. ANSWER -Secure-Random