100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CSE 2221 Final Exam Review. £7.16   Add to cart

Exam (elaborations)

CSE 2221 Final Exam Review.

 2 views  0 purchase

CSE 2221 Final Exam Review.

Preview 3 out of 18  pages

  • June 17, 2024
  • 18
  • 2023/2024
  • Exam (elaborations)
  • Questions & answers
All documents for this subject (10)
avatar-seller
denicetho
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

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller denicetho. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for £7.16. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

79271 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy revision notes and other study material for 14 years now

Start selling
£7.16
  • (0)
  Add to cart