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 6 páginas
Examen

CMSC131 EXAM 2 REVIEW QUESTIONS WITH VERIFIED ANSWERS

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

CMSC131 EXAM 2 REVIEW QUESTIONS WITH VERIFIED ANSWERS

Vista previa del contenido

CMSC131 EXAM 2 REVIEW QUESTIONS WITH
VERIFIED ANSWERS

Name one class discussed in class that is immutable. - Answers - String

When should we define a method as static? - Answers - If it makes no reference to
instance variables.

What is the default value of reference instance variables of a class? - Answers - null

When is space for a local integer variable allocated and when is it recovered? - Answers
- Allocated: when the method is called; recovered: when the method finishes

Why do we never use == to compare floating point numbers? - Answers - Because
floating point numbers are approximations

When is the finally block associated with exceptions executed? - Answers - Always

In which area of memory are objects created? - Answers - heap

When should we define a constant as a static constant? In other words, when should
we usestatic final vs. final while defining a constant? - Answers - We should use static
when all instances of the class will use the same constant value

Based on the following class, indicated whether the statements below are valid or
invalid.

public class Computer
{
private String make;
public Computer(String makeIn)
{
make = makeIn;
}

public void setMake(String makeIn)
{
make = makeIn;
}

public static void info()
{
System.out.println("Computer Sys");
}

, } - Answers - VALID
Computer c1 = new Computer("sun"); c1.setMake("mars");

Computer c4 = new Computer("venus"); c4.info();

Computer.info();

When is the code associated with a finally block executed? - Answers - Always

Which of the following takes care of an object that is no longer referenced by any
variables? - Answers - The garbage collector

for (int i = 1; i <= 8; i += 3)
{
if (i == 4)
{
continue;
}
System.out.println(i);
} - Answers - 1
7

What is the output of the previous code fragment if we replace continue; with break; ? -
Answers - 1

How many objects exist in the following code fragment?

String a, b;
int c; - Answers - 0

The following code compiles. Do you see any problems with the code? Write NONE if
no problems or invalid operations are present. You can assume the method is in a class
that compiles.

public void check(double val, int x)
{
if (x > 0)
{
if (val == 4.5)
{
System.out.println("expected");
}
}
} - Answers - We should not be comparing floating point values.

How many default constructors do we have in the following class?

Información del documento

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

¿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