Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Document preview thumbnail
Vista previa 2 fuera de 12 páginas
Examen

CMSC 131 MIDTERM 2 QUESTIONS WITH VERIFIED ANSWERS

Document preview thumbnail
Vista previa 2 fuera de 12 páginas

CMSC 131 MIDTERM 2 QUESTIONS WITH VERIFIED ANSWERS

Vista previa del contenido

CMSC 131 MIDTERM 2 QUESTIONS WITH VERIFIED
ANSWERS

True/False: In order to run a static method, you must run it for a particular object (the
current object). - Answers - False

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

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

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

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

What default values are used for the variables mentioned above? - Answers - 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? -
Answers - Lots of small ones

What is JUnit? - Answers - 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. - Answers -
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? - Answers - 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? - Answers - Yes

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

What does "this" refer to? - Answers - 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 ? - Answers - 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? - Answers - null

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

What is a copy constructor? Give an example. - Answers - 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)? - Answers - 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? - Answers - top

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

Draw a diagram showing both the Stack and the Heap at the moment this program
terminates: - Answers - 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. - Answers -
TRUE

Información del documento

Subido en
10 de julio de 2026
Número de páginas
12
Escrito en
2025/2026
Tipo
Examen
Contiene
Preguntas y respuestas
$14.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
GEEKA
3.8
(361)
Vendido
2137
Seguidores
1449
Artículos
58516
Última venta
2 días hace



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes