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
What happens if a superclass does not implement Serializable?
A. Serialization will fail completely.
B. Default constructor will initialize the superclass during deserialization.
C. All fields of the superclass will be serialized.
D. Subclass fields will not be serialized.
Default constructor will initialize the superclass during deserialization.
What exception is thrown if a class is deserialized with an incompatible serialVersionUID?
A. SerializationException
B. InvalidObjectException
C. InvalidClassException
D. IOException
InvalidClassException
Which of the following fields would not be serialized?
A. A field declared as public
B. A field declared as transient
C. A field without modifiers
D. A field declared as final
A field declared as transient
What type of architecture is MVC?
A. Component-based
B. Application Layering
C. Architectural Pattern
D. Dynamic Framework
Architectural Pattern
In MVC, which component handles user input?
A. Model
B. View
C. Controller
D. Service
Controller
What does the View in MVC typically use to display data?
A. Observer Pattern
B. ActionListeners
C. Graphical Components
D. Business Logic
Graphical Components
What does the Observer interface require implementing classes to define?
A. notifyObservers()
B. addObserver()
C. update()
D. getData()
update()
Which of the following best describes the role of the Controller?
A. Stores data and business logic
B. Manages the application’s user interface
C. Connects the Model and the View
D. Handles data persistence
Connects the Model and the View
In MVC, what method is used to inform observers of a change in the model?
A. setChanged()
B. repaint()
C. notifyObservers()
D. updateView()
notifyObservers()
Which type of inner class is instantiated without being given a name?
A. Nested Class
B. Method Local Inner Class
C. Anonymous Inner Class
D. Abstract Inner Class
Anonymous Inner Class
Where are Method Local Inner Classes defined?
A. Inside methods
B. Outside all methods in the outer class
C. Inside constructors only
D. In a separate file
Inside constructors only
What is the primary advantage of using inner classes?
A. Improved runtime performance
B. Enhanced readability and encapsulation
C. Simplified inheritance
D. Automatic serialization
Enhanced readability and encapsulation
What kind of relationship does an inner class have with its outer class?
A. Aggregation
B. Inheritance
C. Composition
D. Static association
Composition
Which of the following uses inner classes effectively?
A. Event listeners in GUI applications
B. Data storage in databases
C. Networking for server-client communication
D. File I/O operations
Event listeners in GUI applications
What is the benefit of type erasure in Generics?
A. To improve runtime performance
B. To enable backward compatibility
C. To provide dynamic type-checking
D. To restrict the use of collections
To enable backward compatibility
Which type of bounds restricts a generic to accept only its superclasses?
A. Upper bound
B. Lower bound
C. Wildcard bound
D. Type parameter
Lower bound
What does <?> represent in Generics?
A. A specific type
B. An unknown type
C. A numeric type
D. A bounded type
An unknown type
Why might a wildcard be used in Generics?
A. To limit flexibility in type compatibility
B. To allow a generic method to accept multiple types
C. To enforce compile-time casting
D. To reduce the size of the bytecode
To allow a generic method to accept multiple types
Which of the following is a valid wildcard declaration?
A. List<?>
B. List<T>
C. List<E>
D. List<object></object></E></T>
List<?>
In Java, what is the result of trying to instantiate a generic type parameter?
A. A runtime exception
B. A compilation error
C. A null value
D. It works without issue
A compilation error
What is the primary purpose of bounded wildcards?
A. To restrict type arguments within a range of types
B. To allow any type as an argument
C. To enforce the use of primitive types
D. To enhance performance during runtime
To restrict type arguments within a range of types
Which of the following classes does NOT automatically support serialization?
A. String
B. ArrayList
C. HashMap
D. Thread
Thread
How can you ensure that a field is serialized even if it is transient?
A. Use serialVersionUID
B. Manually write the field in writeObject
C. Use static instead of transient
D. It cannot be done
Manually write the field in writeObject
What method is used to write an object for serialization?
A. writeObject()
B. writeBytes()
C. write()
D. writeStream()
writeObject()
Which Java package is required for serialization?
A. java.util
B. java.lang
C. java.io
D. java.net
java.io
What is the result of deserializing a transient field?
A. It retains its original value.
B. It is re-initialized to its default value.
C. It throws an exception.
D. It retains the serialized value.
It is re-initialized to its default value
How does the View interact with the Model in MVC?
A. Directly manipulates data
B. Passively observes the Model for updates
C. Sends commands for updates
D. Handles data validation
Passively observes the Model for updates
What method is used to add an observer to a model in Java?
A. notifyObservers()
B. addObserver()
C. registerObserver()
D. setChanged()
addObserver()
In the ball example, what triggers the repainting of the View?
A. update() method in View
B. move() method in Model
C. addObserver() method in Controller
D. ActionListener in View
update() method in View
Which component of MVC does not directly interact with the user?
A. Model
B. View
C. Controller
D. Both A and B
Model
What is the key characteristic of the Controller?
A. It holds business logic.
B. It directly displays data.
C. It responds to user events.
D. It manages data persistence.
It responds to user events.
Which type of inner class can be defined inside a method?
A. Anonymous Inner Class
B. Method Local Inner Class
C. Static Nested Class
D. Nested Member Class
Method Local Inner Class
Which of the following is true about Anonymous Inner Classes?
A. They can only implement one interface or extend one class.
B. They can define constructors.
C. They can be serialized.
D. They must be static.
They can only implement one interface or extend one class.
What is the main difference between Inner Classes and Nested Static Classes?
A. Inner Classes do not have access to the outer class.
B. Nested Static Classes do not require an instance of the outer class.
C. Inner Classes cannot be private.
D. Nested Static Classes must implement an interface.
Nested Static Classes do not require an instance of the outer class.
Which of the following can access private members of the outer class?
A. Static Nested Class
B. Anonymous Inner Class
C. Method Local Inner Class
D. All of the above
All of the above
What is a key advantage of using inner classes?
A. They allow extending multiple classes.
B. They improve encapsulation within the outer class.
C. They eliminate the need for multiple files.
D. They simplify static method calls.
They improve encapsulation within the outer class.