COP 3503C Programming Fundamentals
2
Finals Mock Exam Review
(Questions & Solutions)
2025
©2025
, Question 1
In Java, which of the following best distinguishes an abstract class from
an interface?
A) Abstract classes can declare state (fields) and have constructors,
whereas interfaces (prior to Java 8) do not support these features.
B) Interfaces allow multiple inheritance of type, whereas a class can
extend multiple abstract classes.
C) Abstract classes are always completely implemented, while interfaces
require all methods to be abstract.
D) An abstract class does not support method overriding, whereas an
interface does.
ANS: A
Rationale: Abstract classes can hold state (fields) and have
constructors; interfaces traditionally did not allow these features
(although newer Java versions add default methods, the classical
distinction remains). Additionally, while a class can implement multiple
interfaces, it can extend only one abstract class.
---
Question 2
Which statement best describes a lambda expression in modern
programming languages such as Java or C ?
A) It is a named function stored in a variable for reuse.
B) It is an anonymous function that can capture variables from its
enclosing scope.
C) It is a design pattern that enforces immutability.
D) It is an optimization technique used only in compiled languages.
ANS: B
©2025
, Rationale: Lambda expressions are anonymous functions capable of
capturing variables from their surrounding context (if allowed by the
language) and are often used to implement functional interfaces or
delegates.
---
Question 3
In a multi-threaded Java application, which approach is most effective for
ensuring safe access to shared mutable data?
A) Relying solely on the Java garbage collector
B) Using synchronized blocks or methods
C) Employing recursion over iteration
D) Creating global variables to store thread state
ANS: B
Rationale: Synchronized blocks and methods ensure that only one
thread accesses a critical section at a time, preventing race conditions
and ensuring thread safety when working with mutable shared data.
---
Question 4
Regarding generics in Java, which of the following is a correct statement?
A) Generics provide runtime type information that eliminates the need
for casting.
B) They are implemented using type erasure, eliminating generic type
parameters at runtime.
C) Generics enable multiple inheritance of type.
D) They require explicit memory management similar to manual
allocation in C.
ANS: B
©2025
, Rationale: Java implements generics via type erasure, meaning that
generic type information is used at compile time for type checking but is
removed at runtime. This is why casting may still be needed in some
cases.
---
Question 5
When designing custom exception classes in Java, which practice is most
advisable for preserving diagnostic information?
A) Overriding the `finalize()` method
B) Wrapping the original exception as a cause using exception chaining
C) Using print statements to log errors
D) Ignoring the original exception to simplify the error message
ANS: B
Rationale: Exception chaining (by using methods such as `initCause` or
passing the cause to the constructor) preserves the original error
information, which is critical for diagnosing and debugging issues in
production code.
---
Question 6
Which of the following methods is considered the most thread-safe
implementation of the Singleton pattern in Java?
A) Lazy initialization with double-checked locking
B) Eager initialization
C) Enum-based Singleton
D) Creating a new instance every time the getInstance() method is called
ANS: C
Rationale: The enum-based Singleton is thread-safe by design, prevents
©2025
2
Finals Mock Exam Review
(Questions & Solutions)
2025
©2025
, Question 1
In Java, which of the following best distinguishes an abstract class from
an interface?
A) Abstract classes can declare state (fields) and have constructors,
whereas interfaces (prior to Java 8) do not support these features.
B) Interfaces allow multiple inheritance of type, whereas a class can
extend multiple abstract classes.
C) Abstract classes are always completely implemented, while interfaces
require all methods to be abstract.
D) An abstract class does not support method overriding, whereas an
interface does.
ANS: A
Rationale: Abstract classes can hold state (fields) and have
constructors; interfaces traditionally did not allow these features
(although newer Java versions add default methods, the classical
distinction remains). Additionally, while a class can implement multiple
interfaces, it can extend only one abstract class.
---
Question 2
Which statement best describes a lambda expression in modern
programming languages such as Java or C ?
A) It is a named function stored in a variable for reuse.
B) It is an anonymous function that can capture variables from its
enclosing scope.
C) It is a design pattern that enforces immutability.
D) It is an optimization technique used only in compiled languages.
ANS: B
©2025
, Rationale: Lambda expressions are anonymous functions capable of
capturing variables from their surrounding context (if allowed by the
language) and are often used to implement functional interfaces or
delegates.
---
Question 3
In a multi-threaded Java application, which approach is most effective for
ensuring safe access to shared mutable data?
A) Relying solely on the Java garbage collector
B) Using synchronized blocks or methods
C) Employing recursion over iteration
D) Creating global variables to store thread state
ANS: B
Rationale: Synchronized blocks and methods ensure that only one
thread accesses a critical section at a time, preventing race conditions
and ensuring thread safety when working with mutable shared data.
---
Question 4
Regarding generics in Java, which of the following is a correct statement?
A) Generics provide runtime type information that eliminates the need
for casting.
B) They are implemented using type erasure, eliminating generic type
parameters at runtime.
C) Generics enable multiple inheritance of type.
D) They require explicit memory management similar to manual
allocation in C.
ANS: B
©2025
, Rationale: Java implements generics via type erasure, meaning that
generic type information is used at compile time for type checking but is
removed at runtime. This is why casting may still be needed in some
cases.
---
Question 5
When designing custom exception classes in Java, which practice is most
advisable for preserving diagnostic information?
A) Overriding the `finalize()` method
B) Wrapping the original exception as a cause using exception chaining
C) Using print statements to log errors
D) Ignoring the original exception to simplify the error message
ANS: B
Rationale: Exception chaining (by using methods such as `initCause` or
passing the cause to the constructor) preserves the original error
information, which is critical for diagnosing and debugging issues in
production code.
---
Question 6
Which of the following methods is considered the most thread-safe
implementation of the Singleton pattern in Java?
A) Lazy initialization with double-checked locking
B) Eager initialization
C) Enum-based Singleton
D) Creating a new instance every time the getInstance() method is called
ANS: C
Rationale: The enum-based Singleton is thread-safe by design, prevents
©2025