• 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 3 out of 18 pages
Exam (elaborations)

CMSC 131 UMD Midterm 2 UPDATED ACTUAL Questions and CORRECT Answers

Document preview thumbnail
Preview 3 out of 18 pages

CMSC 131 UMD Midterm 2 UPDATED ACTUAL Questions and CORRECT Answers

Content preview

CMSC 131 UMD Midterm 2 UPDATED
ACTUAL Questions and CORRECT
Answers
True/False: In order to run a static method, you must run it for a particular object (the current
object). - CORRECT ANSWER - False


True/False: In order to run an instance method, you must run it for a particular object (the current
object). - CORRECT ANSWER - True



True/False: An instance variable can be declared as "static". - CORRECT ANSWER -
False


True/False: The same class can contain some members that are static and some members that are
non-static. - CORRECT ANSWER - True


Which kinds of variables are given default values if you do not initialize them? (Local/
instance/static? Which ones?) - CORRECT ANSWER - instance and static



What default values are used for the variables mentioned above? - CORRECT ANSWER -
0 for all primitive types (false for boolean, ASCII code 0 for char); "null" for reference variables


When writing JUnit tests, is it better to write many small tests, or a few long ones? - CORRECT
ANSWER - Lots of small ones



What is JUnit? - CORRECT ANSWER - A useful feature of Java that allows us to
quickly write "unit tests" for classes we are writing. The tests can be run conveniently and
repeatedly so that as changes are made to the code we can quickly verify that everything still
works properly!

,Give an example of the correct syntax for "assertTrue" in a JUnit test. - CORRECT
ANSWER - assertTrue(x < 4); // test will pass if and only if the value of x is less than 4


If a JUnit test has several separate assertions in it, will the test continue after one of the
assertions fails? - CORRECT ANSWER - No


If a JUnit test suite has several different JUnit tests in it (separate methods), will the rest of the
tests run after one of them fails? - CORRECT ANSWER - Yes



In what kind of methods does it make sense to use "this"? - CORRECT ANSWER -
Instance methods and constructors.


What does "this" refer to? - CORRECT ANSWER - The "current object".


If you do not write any constructors, what values will instance variables of the following
primitive types be assigned: int, double, boolean, char ? - CORRECT ANSWER - 0 for
int, 0.0 for double, false for boolean, ASCII code 0 for char


If you do not write any constructors, what values will instance variables that are references by
assigned? - CORRECT ANSWER - null


Under what circumstances will Java provide a default constructor for you automatically? -
CORRECT ANSWER - If you do not write any constructors yourself.



What is a copy constructor? Give an example. - CORRECT ANSWER - The copy
constructor accepts an argument that is the same type as the object being constructed. It
initializes the fields of the current object to match that of the parameter. Example:
public Cat(Cat x) {
numWhiskers = x.numWhiskers;
name = x.name;
}

, What is a Stack (in general, not just in Java)? - CORRECT ANSWER - A stack is a
simple linear data type in which elements are both inserted ("pushed") and removed ("popped")
from the same end. (We usually picture the stack vertically, and say that we "push" and "pop"
items from the top.)


When you push an entry into the stack does it go on the top or bottom? - CORRECT
ANSWER - top


When you pop an entry from the stack, does it come off the top or bottom? - CORRECT
ANSWER - top


Draw a diagram showing both the Stack and the Heap at the moment this program terminates: -
CORRECT ANSWER - public static void main(String[] args) {


int x = 0;
String y = new String("xyz");
String z = y;
String a = new String(y);
f(x, y, z, a);
}


public static void f(int j, String k, String m, String r) {
System.exit(1);
}


True/False: In java, when you pass a reference variable as an argument to a method, it is possible
for the method to modify the object to which the variable refers. - CORRECT ANSWER -
TRUE

Document information

Uploaded on
October 26, 2025
Number of pages
18
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$12.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.
STANFORDGRADESS
4.0
(241)
Sold
1674
Followers
109
Items
121810
Last sold
1 hour 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