OOPMIDTERM Flashcards

1
Q

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

A

To allow abstraction over types and enhance code reusability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

Runtime performance improvement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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>

A

public class Sample<E> {}</E>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What keyword is used for upper-bounding a generic type?
A. super
B. extends
C. implements
D. final

A

extends

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which modifier is used to exclude a field from serialization in Java?
A. static
B. final
C. transient
D. volatile

A

transient

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What exception is thrown if serialVersionUID does not match during deserialization?
A. ClassCastException
B. IOException
C. InvalidClassException
D. IllegalArgumentException

A

InvalidClassException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

To handle the business logic and data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which component of MVC is responsible for handling user interactions?
A. Model
B. View
C. Controller
D. Database

A

Controller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

Improved program execution speed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In the ball example, what class is extended to enable broadcasting in the Model?
A. Observable
B. Observer
C. JPanel
D. ActionListener

A

Observable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

To define and instantiate a class for one-time use

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which method must be implemented when using the Observer interface?
A. setChanged()
B. notifyObservers()
C. update()
D. getX()

A

update()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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.

A

The View observes the Model.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

Anonymous Inner Class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which of the following is NOT a valid type parameter convention?
A. T - Type
B. K - Key
C. V - Value
D. S - Stream

A

S - Stream

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What type parameter would you typically use for numeric values?
A. T
B. N
C. E
D. V

A

N

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

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.

A

Generics only work with objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Which of the following can enforce bounds in a generic class?
A. T super
B. T extends
C. T implements
D. T instanceOf

A

T extends

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

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

A

To apply generics only to specific methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

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

A list that can store only Integer objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

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>

A

Map<K, V>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Which interface must be implemented for an object to be serializable?
A. Serializable
B. Cloneable
C. Comparable
D. Externalizable

A

Serializable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

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

A

To identify versions of serialized classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Which modifier would ensure a field is not included during serialization?
A. protected
B. volatile
C. transient
D. static

A

transient

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

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.

A

Default constructor will initialize the superclass during deserialization.

26
Q

What exception is thrown if a class is deserialized with an incompatible serialVersionUID?
A. SerializationException
B. InvalidObjectException
C. InvalidClassException
D. IOException

A

InvalidClassException

27
Q

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

A field declared as transient

28
Q

What type of architecture is MVC?
A. Component-based
B. Application Layering
C. Architectural Pattern
D. Dynamic Framework

A

Architectural Pattern

29
Q

In MVC, which component handles user input?
A. Model
B. View
C. Controller
D. Service

A

Controller

30
Q

What does the View in MVC typically use to display data?
A. Observer Pattern
B. ActionListeners
C. Graphical Components
D. Business Logic

A

Graphical Components

31
Q

What does the Observer interface require implementing classes to define?
A. notifyObservers()
B. addObserver()
C. update()
D. getData()

A

update()

32
Q

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

A

Connects the Model and the View

33
Q

In MVC, what method is used to inform observers of a change in the model?
A. setChanged()
B. repaint()
C. notifyObservers()
D. updateView()

A

notifyObservers()

34
Q

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

A

Anonymous Inner Class

35
Q

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

A

Inside constructors only

36
Q

What is the primary advantage of using inner classes?
A. Improved runtime performance
B. Enhanced readability and encapsulation
C. Simplified inheritance
D. Automatic serialization

A

Enhanced readability and encapsulation

37
Q

What kind of relationship does an inner class have with its outer class?
A. Aggregation
B. Inheritance
C. Composition
D. Static association

A

Composition

38
Q

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

A

Event listeners in GUI applications

39
Q

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

A

To enable backward compatibility

40
Q

Which type of bounds restricts a generic to accept only its superclasses?
A. Upper bound
B. Lower bound
C. Wildcard bound
D. Type parameter

A

Lower bound

41
Q

What does <?> represent in Generics?
A. A specific type
B. An unknown type
C. A numeric type
D. A bounded type

A

An unknown type

42
Q

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

A

To allow a generic method to accept multiple types

43
Q

Which of the following is a valid wildcard declaration?
A. List<?>
B. List<T>
C. List<E>
D. List<object></object></E></T>

A

List<?>

44
Q

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

A compilation error

45
Q

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

A

To restrict type arguments within a range of types

46
Q

Which of the following classes does NOT automatically support serialization?
A. String
B. ArrayList
C. HashMap
D. Thread

A

Thread

47
Q

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

A

Manually write the field in writeObject

48
Q

What method is used to write an object for serialization?
A. writeObject()
B. writeBytes()
C. write()
D. writeStream()

A

writeObject()

49
Q

Which Java package is required for serialization?
A. java.util
B. java.lang
C. java.io
D. java.net

A

java.io

50
Q

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.

A

It is re-initialized to its default value

51
Q

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

A

Passively observes the Model for updates

52
Q

What method is used to add an observer to a model in Java?
A. notifyObservers()
B. addObserver()
C. registerObserver()
D. setChanged()

A

addObserver()

53
Q

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

A

update() method in View

54
Q

Which component of MVC does not directly interact with the user?
A. Model
B. View
C. Controller
D. Both A and B

A

Model

55
Q

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.

A

It responds to user events.

56
Q

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

A

Method Local Inner Class

57
Q

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.

A

They can only implement one interface or extend one class.

58
Q

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.

A

Nested Static Classes do not require an instance of the outer class.

59
Q

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

A

All of the above

60
Q

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.

A

They improve encapsulation within the outer class.