CSE 2221 Final Exam Review/22 Complete Q’s and
A’s
For a method formal parameter p, which parameter mode guarantees that
#p cannot appear n the ensures clause for the method's contract?
a. clears
b. replaces
c. restores
d. updates - - B. replaces
- You may reason about the behavior of Java code involving immutable
types exactly as if they were primitive types because:
a. "Immutable" and "primitive" are synonyms; there is no difference between
them
b. Computations involving immutable types are just as efficient as those
involving primitive types
c. Aliasing, which can happen with immutable types but not primitive types,
cannot cause trouble because object values for immutable types cannot be
changed
d. In any code where an immutable type is used in a way where it would not
behave like a primitive type, it causes a Java compile-time error - - C.
Aliasing
- Assume n is an int variable. Which Java expression is true exactly when n is
an odd number (not divisible by 2) and should be used to check for this
situation?
a. n%2==0
b. n%2!=0
c. n%2==1
d. n%2!=1 - - b. n%2!=0
- what are the values of str and num after the call to foo?
private static void foo(String s, NaturalNumber n){
s="Columbus, " +s;
n=new NaturalNumber2(43210);
}
...String str = "Ohio";
NaturalNumber num=new NaturalNumber2(314);
foo(str,num);
a. str="Ohio", num=314
b. str="Columbus, Ohio", num=314
c. str="Ohio", num=43210
d. str="Columbus, Ohio", num=43210 - - c. str="Ohio", num=314
- What are the values of array and index after the call to bar?
, private static void bar(int[] a, int i){
a[i]++;
i++;
}
...
int[] array={1,2,3,4};
int index=1;
bar(array,index);
a. array={1,2,3), index=1
b. array={1,2,3), index=2
c. array={1,3,3), index=1
d. array={1,3,3), index=2 - - c. array={1,3,3), index=1
- A type is an immutable type if:
a. It is illegal to copy a reference of that type, so there can be no aliasing.
b. For every instance method of that type, this and every other parameter of
that type is a restores-mode parameter
c. That type has a no-argument constructor.
d. A function method may not return a result of that type. - - b. For every
instance method of that type, this and every other parameter of that type is
a restores-mode parameter
- Which of the following test cases should not be performed?
a. routine or otherwise trivially simple test cases
b. test cases that would cause no change to parameters
c. boundary cases, based on the variables passed in
d. test cases which do not meet method preconditions - - d. test cases which
do not meet method preconditions
- Which is true of JUnit testing when the unit under test is a single method?
A. Very thorough JUnit testing can prove the correctness of the method body.
b. JUnit testing is generally considered an expensive waste of time in
industry
c. A single JUnit test case can show the presence of a defect in the method
body.
d. A single JUnit test case can show the absence of defects in the method
body, at least for the particular choice of inputs in that test case - - c. A
single JUnit test case can show the presence of a defect in the method body.
- After execution of the following code, what are the declared type (static
type) and the object type (dynamic type) of nCopy?
NaturalNumber n = new NaturalNumber1L();
NauturalNumber nCopy=new NaturalNumber2();
a. Declared type is NaturalNumber, object type is NaturalNumber1L
b. Declared type is NaturalNumber, object type is NautralNumber2