Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 4 out of 82 pages
Exam (elaborations)

SNHU IT 145 Foundations in App Development Midterm Exam | 167 Java Practice Questions & Verified Answers (Latest 2026/2027 Guide)

Document preview thumbnail
Preview 4 out of 82 pages

Prepare confidently for your Southern New Hampshire University midterm with this comprehensive study bank featuring 167 verified practice questions and detailed explanations. This 2026/2027 update targets foundational object-oriented programming concepts, ensuring complete mastery over Java syntax, class structures, and method implementation. Step-by-step code solutions walk you through array manipulation, logic loops, and variable scopes so you can easily secure an A on your IT-145 midterm exam.

Content preview

IT 145 Foundation in Application Development Midterm Exam
Practice Questions and Detailed Solutions Latest Update
2026/2027 | Classes, Methods, Arrays, Verified Answers - 167
Questions

This midterm exam assesses foundational knowledge of object-oriented programming in Java, focusing on class
design, method implementation, arrays, and program logic. It requires critical thinking and application of
concepts to non-trivial coding scenarios. It contains 167 multiple-choice questions, each with four distractors and
a fully worked rationale that explains why the keyed answer is correct. Questions are organized into clearly
labelled sections that mirror the major content areas of the course. Targeted learning outcomes include: Design
and implement Java classes with appropriate encapsulation and visibility modifiers.; Analyze and trace method
calls, including recursion and parameter passing.; Manipulate arrays and ArrayLists to solve complex
data-processing problems.; Identify and fix common coding errors and anti-patterns in Java code.. Every item has
been reviewed for clinical accuracy, current guidelines, and clarity so that students can study with confidence and
self-correct as they work through the bank. Use it as a high-yield review immediately before the exam, or as a
structured practice tool during the unit - the rationales double as concise teaching notes. The recommended
writing time is 2 hours 30 minutes, with a passing score of 70%. Aligned with Aligned with ACM/IEEE Computer
Science Curricula 2023 and ABET computing accreditation standards. standards and reflects the question style
commonly seen on accredited program examinations. Students consistently achieving above the cut score on this
bank have historically gone on to earn A+ on the corresponding course exam. Read every stem carefully -

Section 1: General (Questions 1-167)

1 Consider the following class definitions. What is the output when
the main method is executed?
A) 2 4
B) 4 2
C) 2 2
D) 4 4
Answer: B
Rationale: The method setVals is called on obj1 with x=1, y=2. Inside
setVals, a new A object is created and assigned to the parameter obj,
so obj now refers to a different object. Changes to obj.x and obj.y
affect this new object, not the caller's obj1. Therefore, obj1 remains
with x=2, y=4. The output is '4 2' because the getX() and getY()
methods are called on obj1, which has x=2 and y=4.
2 Which of the following statements best explains the behavior of the
`finalize()` method in Java?

,A) It is guaranteed to be called exactly once before an object is
garbage collected.
B) It is called by the garbage collector on an object when the object
is no longer reachable, but the timing is non-deterministic.
C) It can be used to force immediate garbage collection by calling
`System.gc()`.
D) It is deprecated and should never be used in modern Java code.
Answer: B
Rationale: The `finalize()` method is invoked by the garbage collector
when an object is deemed unreachable, but the exact time is not
deterministic. It is not guaranteed to run exactly once, and it is indeed
deprecated for general use, but it is still a valid concept. Option B
correctly describes the core behavior without overgeneralizing.
3 Given the following array declaration: `int[] arr = {3, 1, 4, 1, 5, 9, 2,
6};`. Which code snippet correctly rotates the array elements to the
left by two positions?
A) int temp = arr[0]; for (int i = 0; i < arr.length-1; i++) arr[i] =
arr[i+1]; arr[arr.length-1] = temp;
B) int[] temp = {arr[0], arr[1]}; for (int i = 0; i < arr.length-2; i++)
arr[i] = arr[i+2]; arr[arr.length-2] = temp[0]; arr[arr.length-1] =
temp[1];
C) int[] temp = new int[arr.length]; for (int i = 0; i < arr.length; i++)
temp[(i+2)%arr.length] = arr[i]; arr = temp;
D) int[] temp = new int[arr.length]; for (int i = 2; i < arr.length; i++)
temp[i-2] = arr[i]; temp[arr.length-2] = arr[0]; temp[arr.length-1] =
arr[1]; arr = temp;
Answer: C
Rationale: Option C correctly shifts each element to the left by two
positions using modulo arithmetic to wrap around. Option A rotates
by one position only. Option B incorrectly overwrites the first two
elements and then tries to place temporary values at the end, but it
loses the original values. Option D incorrectly places the first two

,elements at the end but does not preserve the order of the rest correctly
(it shifts them left by two, which is correct, but the assignment to
temp[arr.length-2] and temp[arr.length-1] overwrites the values that
should be there from the loop, causing errors).
4 What is the output of the following recursive method when called
with `mystery(5)`?
A) 15
B) 10
C) 20
D) 5
Answer: A
Rationale: The method `mystery` returns the sum of integers from 1 to
n. For n=5, it returns 5 + mystery(4) = 5 + (4 + mystery(3)) = ... =
5+4+3+2+1 = 15. The correct answer is 15.
5 Which of the following statements about the `==` operator and the
`equals()` method in Java is correct?
A) The `==` operator compares object references, while `equals()` is
always overridden to compare object contents.
B) The `equals()` method can be used to compare primitive values,
but `==` cannot.
C) For any two objects `a` and `b`, if `a == b` is true, then
`a.equals(b)` must be true.
D) The `==` operator compares object contents for String objects, so
`"abc" == "abc"` is always true.
Answer: C
Rationale: If `a == b` is true, it means they refer to the same object, so
`a.equals(b)` will also return true (since the same object is equal to
itself). Option A is incorrect because `equals()` is not always
overridden; it uses identity by default. Option B is incorrect because
`equals()` is for objects, not primitives. Option D is incorrect because
`==` compares references for Strings, not contents, unless they are

, interned or compile-time constants.
6 Consider the following code snippet. Which exception is thrown
and why?
A) ArrayIndexOutOfBoundsException because the loop condition `i
<= arr.length` accesses an out-of-bounds index.
B) NullPointerException because the array is not initialized.
C) ArithmeticException because of division by zero.
D) No exception; the code runs without error.
Answer: A
Rationale: The loop `for (int i = 0; i <= arr.length; i++)` will iterate
from 0 to arr.length inclusive, and when i equals arr.length, accessing
arr[i] causes an ArrayIndexOutOfBoundsException. The array is
initialized, so no NullPointerException. There is no division by zero.
The code will throw an exception.
7 Which of the following is the correct way to create a
two-dimensional array in Java with 3 rows and 4 columns, all
initialized to 0?
A) int[][] arr = new int[3][4];
B) int[][] arr = new int[3][];
C) int[][] arr = { {0,0,0,0}, {0,0,0,0}, {0,0,0,0} };
D) Both A and C.
Answer: D
Rationale: Option A creates a 2D array with 3 rows and 4 columns,
and all elements are initialized to 0 by default. Option C explicitly
initializes a 2D array with the same dimensions and all zeros. Both are
valid. Option B creates a jagged array with 3 rows but no columns
specified.
8 What is the primary difference between an abstract class and an
interface in Java?

Document information

Uploaded on
August 24, 2026
Number of pages
82
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$27.79

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.
StudentArchive
3.9
(7)
Sold
35
Followers
1
Items
1353
Last sold
5 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