• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 9 pages
Exam (elaborations)

CMSC 131 Object Oriented Programming I Unit Test 4 - Questions with Correct Answers (Verified Update)

Document preview thumbnail
Preview 2 out of 9 pages

CMSC 131 Object Oriented Programming I Unit Test 4 (University of Maryland): 17 exam questions with verified correct answers and rationales, for CMSC 131 at University of Maryland. 9 pages, 2026 verified update. Sample questions covered: What can be tested to distinguish an existing empty array from a nonempty array? | int[] a = new int[6]; a[0] = 5; What is the value of a[1]? | Amount a = new Doubled(6); The final expression is (). Amount declares int value(). Doubled stores its constructor argument and returns twice t | Which statement best characterizes autoboxing?

Content preview

CMSC 131 Object-Oriented Programming I: Unit Test 4
Questions and Answers - University of Maryland

1. What can be tested to distinguish an existing empty array from a nonempty array?
A. The copied reference still points to the same array
B. Whether its length is zero
C. A linear scan
D. The two array elements may refer to the same mutable object
Answer: B. Whether its length is zero
Rationale: An empty array is an allocated array with length zero and no valid element positions.


2. int[] a = new int[6]; a[0] = 5; What is the value of a[1]?
A. 5
B. 1
C. -1
D. 0
Answer: D. 0
Rationale: Only cell zero was assigned. Other int array cells retain their default zero value.


3. Amount a = new Doubled(6); The final expression is a.value(). Amount declares int value(). Doubled
stores its constructor argument and returns twice that number from value(). What is returned?
A. 18
B. 12
C. 8
D. 6
Answer: B. 12
Rationale: The contract permits a call through Amount, but the implementing object determines the
execution result.

,4. int[] a = { 5, 6 }; touch(a); The final expression is a[0]. Given static void touch(int[] z) { z[0] += 5; },
what does the expression return?
A. 5
B. 10
C. 6
D. 11
Answer: B. 10
Rationale: The parameter holds a copy of the array reference, so writing the first cell affects the
shared array.


5. Which statement best characterizes autoboxing?
A. Autoboxing converts an eligible primitive value to its corresponding wrapper in an appropriate
context.
B. compareTo communicates less than, equal to and greater than through negative, zero and
positive results.
C. ArrayList.get uses a zero-based position and retrieves an element without removing it.
D. Comparable defines a natural ordering contract through compareTo.
Answer: A. Autoboxing converts an eligible primitive value to its corresponding wrapper in an
appropriate context.
Rationale: Autoboxing converts an eligible primitive value to its corresponding wrapper in an
appropriate context. Consider this example. Assigning an int value to Integer occurs without an
explicit factory call.


6. ArrayList<Integer> a = new ArrayList<>(); a.add(2); a.add(3); a.add(0, 7); What is the value of
a.get(1)?
A. 8
B. 3
C. 2
D. 7
Answer: C. 2
Rationale: Insertion at index zero shifts the previous first element to index one.

Document information

Uploaded on
November 20, 2026
Number of pages
9
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$8.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
DrJon
3.8
(161)
Sold
620
Followers
188
Items
29629
Last sold
2 days ago




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

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions