100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Exam (elaborations)

CSE 2221 Final Exam Review.

Rating
-
Sold
-
Pages
18
Grade
A+
Uploaded on
17-06-2024
Written in
2023/2024

CSE 2221 Final Exam Review.

Institution
Course

Content preview

CSE 2221 Final Exam Review

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 - ANS-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 - ANS-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 - ANS-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 - ANS-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};
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 - ANS-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. - ANS-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 - ANS-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 - ANS-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(n);
a. Declared type is NaturalNumber, object type is NaturalNumber1L
b. Declared type is NaturalNumber, object type is NautralNumber2
c. Declared type is NaturalNumber2, object type is NaturalNumber1L
d. Declared type is NaturalNumber2, object type is NaturalNumber - ANS-b. Declared
type is NaturalNumber, object type is NautralNumber2

If you write class C implements interface I, the Java compiler checks:
a. Whether I overrides all the methods of C
b. Whether C inherits all the methods of I
c. Whether each method in I has a method body in C
d. Whether each method body in C is a correct implementation of the contract for that
method in I - ANS-c. Whether each method in I has a method body in C

Consider the following code:
int x=80;
if (x>70){
x=40;
}else if (x<90){
x=20;
}
if (x>30){
x=60;
}
a. 20
b. 40
c. 60
d. 80 - ANS-C. 60

In design-by-contract, the code responsible for making sure the precondition (requires
clause) is true when a method is called is:
a. the code that implements the method
b. the client code that calls the method
c. both the client and the implementation code
d. neither the client nor the implementation code - ANS-b. the client code that calls the
method

Written for

Institution
Study
Course

Document information

Uploaded on
June 17, 2024
Number of pages
18
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$10.54
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
AASOCR

Get to know the seller

Seller avatar
AASOCR American InterContinental University
Follow You need to be logged in order to follow users or courses
Sold
7
Member since
2 year
Number of followers
2
Documents
4856
Last sold
2 days ago

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions