OOPMIDTERM Flashcards
What is the purpose of Generics in Java?
A. To limit the type of objects created in a class
B. To allow abstraction over types and enhance code reusability
C. To handle multiple types of data without using specific classes
D. To make Java programs run faster
To allow abstraction over types and enhance code reusability
Which of the following is NOT a benefit of using Generics?
A. Abstraction over types
B. Compile-time type safety
C. Runtime performance improvement
D. Reducing the need for casting
Runtime performance improvement
Which syntax is used to declare a generic class?
A. public class Sample {}
B. public class Sample<E> {}
C. public class<E> Sample {}
D. public<E> class Sample {}</E></E></E>
public class Sample<E> {}</E>
What keyword is used for upper-bounding a generic type?
A. super
B. extends
C. implements
D. final
extends
Which modifier is used to exclude a field from serialization in Java?
A. static
B. final
C. transient
D. volatile
transient
What exception is thrown if serialVersionUID does not match during deserialization?
A. ClassCastException
B. IOException
C. InvalidClassException
D. IllegalArgumentException
InvalidClassException
What is the primary purpose of the Model in the MVC framework?
A. To manage user inputs
B. To handle the business logic and data
C. To render the user interface
D. To control the application flow
To handle the business logic and data
Which component of MVC is responsible for handling user interactions?
A. Model
B. View
C. Controller
D. Database
Controller
Which of the following is NOT an advantage of the MVC framework?
A. Easy code maintenance
B. Clear separation of concerns
C. Improved program execution speed
D. Parallel development
Improved program execution speed
In the ball example, what class is extended to enable broadcasting in the Model?
A. Observable
B. Observer
C. JPanel
D. ActionListener
Observable
What is the purpose of an Anonymous Inner Class?
A. To create complex algorithms
B. To define and instantiate a class for one-time use
C. To simplify method overloading
D. To replace the outer class
To define and instantiate a class for one-time use
Which method must be implemented when using the Observer interface?
A. setChanged()
B. notifyObservers()
C. update()
D. getX()
update()
Which part of the MVC framework updates the view upon changes in the model?
A. The Controller calls the View directly.
B. The View observes the Model.
C. The Model updates the Controller.
D. The Controller re-renders the View.
The View observes the Model.
What type of inner class is defined without a name and for one-time use?
A. Inner Class
B. Method Local Inner Class
C. Anonymous Inner Class
D. Nested Inner Class
Anonymous Inner Class
Which of the following is NOT a valid type parameter convention?
A. T - Type
B. K - Key
C. V - Value
D. S - Stream
S - Stream
What type parameter would you typically use for numeric values?
A. T
B. N
C. E
D. V
N
Why can’t primitive types be used directly in Generics?
A. They lack the required methods.
B. Generics only work with objects.
C. They are less efficient.
D. They are not serialized.
Generics only work with objects.
Which of the following can enforce bounds in a generic class?
A. T super
B. T extends
C. T implements
D. T instanceOf
T extends
What is the purpose of a generic method?
A. To enforce runtime type safety
B. To apply generics only to specific methods
C. To limit the size of a collection
D. To prevent inheritance in methods
To apply generics only to specific methods
In the context of Generics, what does List<Integer> indicate?
A. A list restricted to int values
B. A list that can store only Integer objects
C. A generic list without type enforcement
D. A list for both int and Integer values</Integer>
A list that can store only Integer objects
Which generic collection would you use to store key-value pairs?
A. List<T>
B. Set<T>
C. Map<K, V>
D. Queue<E></E></T></T>
Map<K, V>
Which interface must be implemented for an object to be serializable?
A. Serializable
B. Cloneable
C. Comparable
D. Externalizable
Serializable
What is the main purpose of the serialVersionUID?
A. To identify versions of serialized classes
B. To enhance runtime performance
C. To store metadata about the class
D. To generate hash values for objects
To identify versions of serialized classes
Which modifier would ensure a field is not included during serialization?
A. protected
B. volatile
C. transient
D. static
transient